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