public ActionResult Create(CategoryModel model) { if (ModelState.IsValid) { var category = new Category(); category.Name = model.Name; using (_dbContext = new karrykartEntities()) { _dbContext.Categories.Add(category); _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "Category created successfully with categoryID=" + category.CategoryID, "Create", "CategoryController", User.Identity.Name); Success("Category is created successfully.", true); return RedirectToAction("Index", "Category"); } } return View(); }
public ActionResult Edit(CategoryModel model) { if (ModelState.IsValid) { using (_dbContext =new karrykartEntities()) { var category = _dbContext.Categories.Find(model.CategoryID); category.Name = model.Name; _dbContext.Entry(category).State = System.Data.Entity.EntityState.Modified; _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "The category has been edited successfully,category ID= " + model.CategoryID, "Edit", "CategoryController", User.Identity.Name); Success("The category has been edited successfully.", true); return RedirectToAction("Index", "Category"); } } return View(); }