0

Do you have any suggestions on how one might one split the "action method" (see code below) into a separate DAL and BLL?

public ActionResult GetLogs() {
        //set up your connection
        string connectionString = ConfigurationManager.ConnectionStrings["DbConnString"].ConnectionString;
        using var connection = new MySqlConnection(connectionString);
        using var command = new MySqlCommand("Get_AccessLog", connection) { CommandType = CommandType.StoredProcedure };
        connection.Open();
        
        // define a list to hold your records
        var data = new List<GetLogs>();
        using var reader = command.ExecuteReader();
        
        //loop through the reader (i.e. itenerate each row returned by your stored procedure
        while (reader.Read())
        {
            // Create a new log record based on the db row
            data.Add(new GetLogs()
            {
                LogActivityId = reader.GetInt32(0),
                LogActivityName = reader.GetString(1),
                LogActivityDesc = reader.GetString(2)
            });
        }
        //Return the view along with the logs
        return View("GetLogs", data); }
dat
  • 1,580
  • 1
  • 21
  • 30
Rajnikant
  • 1
  • 5
  • Hello Guys! Can some one help me in resolving the above issue? – Rajnikant Mar 21 '23 at 09:19
  • the comment is read only by whoever is reading the question, so why solicit an answer? – weirdgyn Mar 24 '23 at 16:19
  • anyway I don't see any business logic here ... – weirdgyn Mar 24 '23 at 16:22
  • I would like to separate the code written here respective DAL & BLL. – Rajnikant Mar 25 '23 at 18:11
  • to *separate* something the way you want, you need two identifiable pieces of code: one that implements the data handling part and one that implements the business logic ... here's just the part that implements the data handling and so you'd have in any case only the DAL. Maybe you have to go a little further and describe what your business logic is? What will be the data to be processed by the BLL? – weirdgyn Mar 26 '23 at 07:54
  • put it in a different way if your BLL primitive entity is `ActionResult` you're done... of course this's true only if you meant a general approach to DAL & BLL if you want to be compliant with a standard then you need something different – weirdgyn Mar 26 '23 at 08:15

0 Answers0