public ActionResult Create(int personId) { ViewBag.PersonId = personId; var address = new Address(); return View(address); }
public ActionResult Edit(int personId, Address address) { if (ModelState.IsValid) { var person = personRepository.Get(personId); personRepository.SaveAddress(personId, address); return RedirectToAction("Details", "Home", new { id = personId }); } ViewBag.PersonId = personId; return View(address); }
public void SaveAddress(int personId, Address address) { var person = People.First(p => p.Id == personId); if (address.Id.HasValue) { var indx = person.Addresses.FindIndex(p => p.Id == address.Id); if (indx >= 0) person.Addresses[indx] = address; else person.Addresses.Add(address); } else { address.Id = GetNextId(person.Addresses); person.Addresses.Add(address); } }