public ActionResult Create(Zone zone) { if (ModelState.IsValid) { zoneRepository.InsertOrUpdate(zone); zoneRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossibleWaiters = waiterRepository.All; ViewBag.PossibleRestaurants = restaurantRepository.All; return View(); } }
public void InsertOrUpdate(Zone zone) { if (zone.Id == default(System.Guid)) { // New entity zone.Id = Guid.NewGuid(); context.Zones.Add(zone); } else { // Existing entity context.Entry(zone).State = EntityState.Modified; } }