How to split below action method code into separate DAL & BLL in asp.net mvc?

41 views Asked by At

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); }
0

There are 0 answers