public List <CategoryDM> Read(SqlParameter[] parameters, string statement) { using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand(statement, connection)) { command.CommandType = CommandType.StoredProcedure; if (parameters != null) { command.Parameters.AddRange(parameters); } connection.Open(); SqlDataReader data = command.ExecuteReader(); List <CategoryDM> categories = new List <CategoryDM>(); while (data.Read()) { CategoryDM category = new CategoryDM(); category.CtgyId = data["CtgyId"].ToString(); category.Category = data["Category"].ToString(); categories.Add(category); } return(categories); } } }
public void CreateCategory(CategoryDM category) { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Category", category.Category) }; dataWriter.Write(parameters, "CreateCategory"); logs.LogError("Event", "A category has been created", "Class:CategoryDAO, Method: CreateCategory"); }
public void EditCategoryById(CategoryDM category) { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Category", category.Category) , new SqlParameter("@Id", category.CtgyId) }; dataWriter.Write(parameters, "UpdateCategory"); logs.LogError("Event", "An category has been updated", "Class: CategoryDAO, Method: UpdateCategory"); }