public ActionResult EditCustomer(Customer customer) { if (ModelState.IsValid) { repository.SaveChanges(customer); TempData["message"] = "User was changed"; return RedirectToAction("Index"); } else { return View(customer); } }
public void SaveChanges(Customer customer) { if (customer.CustomerID == 0) { context.Customers.Add(customer); } else { Customer dbEntry = context.Customers.Find(customer.CustomerID); if (dbEntry != null) { dbEntry.Name = customer.Name; dbEntry.Surname = customer.Surname; dbEntry.Telephone = customer.Telephone; dbEntry.Address = customer.Address; } } context.SaveChanges(); }