public ActionResult Add(Restaurant objRestaurant) { if (string.IsNullOrEmpty(objRestaurant.Name)) { ModelState.AddModelError("Name", "Please enter the Name"); } if (ModelState.Values.SelectMany(s => s.Errors).Count() > 0) { return View(objRestaurant); } objRestaurant.CreatedDtm = DateTime.Now; objRestaurant.Status = 1; objContext.ContextRestaurant.Add(objRestaurant); objContext.SaveChanges(); return RedirectToAction("List"); }
public ActionResult Edit(Restaurant objRestaurant) { if (string.IsNullOrEmpty(objRestaurant.Name)) { ModelState.AddModelError("Name", "Please enter the Name"); } if (ModelState.Values.SelectMany(s => s.Errors).Count() > 0) { return View(objRestaurant); } Restaurant objRestaurantExist = objContext.ContextRestaurant.SingleOrDefault(s => s.Id == objRestaurant.Id); if (objRestaurantExist != null) { objRestaurantExist.Name = objRestaurant.Name; objContext.SaveChanges(); } return RedirectToAction("List"); }