public ActionResult Create(Restaurant restaurant) { if (ModelState.IsValid) { restaurantRepository.InsertOrUpdate(restaurant); restaurantRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(Restaurant restaurant) { if (restaurant.Id == default(System.Guid)) { // New entity restaurant.Id = Guid.NewGuid(); context.Restaurants.Add(restaurant); } else { // Existing entity context.Entry(restaurant).State = EntityState.Modified; } }