public ActionResult Edit(int?id) { PhonesService phonesService = new PhonesService(); PhonesEditVM model = new PhonesEditVM(); TryUpdateModel(model); Phone phone; if (!id.HasValue) { phone = new Phone(); } else { phone = phonesService.GetByID(id.Value); if (phone == null) { if (phonesService.GetContact(model.ContactID) == null) { return(this.RedirectToAction <ContactsController>(c => c.List())); } return(this.RedirectToAction(c => c.List(), new { ContactID = model.ContactID })); } model.ContactID = phone.ContactID; } Mapper.Map(phone, model); return(View(model)); }
public ActionResult Edit() { UnitOfWork unit = new UnitOfWork(); PhonesService phoneService = new PhonesService(unit); PhoneEditVM model = new PhoneEditVM(); TryUpdateModel(model); Phone p; if (!ModelState.IsValid) { return(View(model)); } if (model.ID != 0) { p = phoneService.GetByID(model.ID); } else { p = new Phone(); } Mapper.Map(model, p); phoneService.Save(p); return(this.RedirectToAction(c => c.List(), new { contactID = model.ContactID })); }
public ActionResult Edit() { PhonesService phonesService = new PhonesService(); PhonesEditVM model = new PhonesEditVM(); TryUpdateModel(model); if (phonesService.GetContact(model.ContactID) == null) { return(this.RedirectToAction <ContactsController>(c => c.List())); } Phone phone; if (model.ID == 0) { phone = new Phone(); } else { phone = phonesService.GetByID(model.ID); if (phone == null) { return(this.RedirectToAction(c => c.List(), new { ContactID = model.ContactID })); } } if (!ModelState.IsValid) { return(View(model)); } Mapper.Map(model, phone); phonesService.Save(phone); return(this.RedirectToAction(c => c.List(), new { ContactID = model.ContactID })); }