public IActionResult Edit(CustomerEditModel model) { if (ModelState.IsValid) { var customer = _context.Clients .Include(x => x.DistrictToClients) .Include(x => x.TypesHousingToCustomers) .Include(x => x.Phones) .Single(x => x.Id == model.EditId); model.UpdateEntity(customer); model.UpdateDistricts(customer); model.UpdateHousingTypes(customer); _context.Update(customer); _context.SaveChanges(); return RedirectToAction("Index"); } return View("Save", model); }
public IActionResult Create(CustomerEditModel model) { if (ModelState.IsValid) { var customer = new Customer(); model.UpdateEntity(customer); _context.Clients.Add(customer); _context.SaveChanges(); model.UpdateDistricts(customer); model.UpdateHousingTypes(customer); _context.SaveChanges(); return RedirectToAction("Index"); } return View("Save",model); }