public ActionResult Edit(ProductCategory productCategory) { if (ModelState.IsValid) { shoeStoreRepository.SaveProductCategory(productCategory); TempData["message"] = MessageHelper.BuildMessage(EnumSevereLevel.Success, string.Format("{0} has been created!", productCategory.ProductCategoryName)); return RedirectToAction("List"); } else { //There is something wrong with the data values TempData["message"] = MessageHelper.BuildMessage(EnumSevereLevel.Error, "There is something wrong with the data values, please check!"); return View(productCategory); } }
public void SaveProductCategory(ProductCategory productCategory) { if (productCategory.ProductCategoryId == 0) { context.ProductCategories.Add(productCategory); } else { ProductCategory dbEntry = context.ProductCategories.Find(productCategory.ProductCategoryId); if (dbEntry != null) { dbEntry.ProductCategoryName = productCategory.ProductCategoryName; dbEntry.Sequence = productCategory.Sequence; } } context.SaveChanges(); }