public ActionResult CreateEdit(int?id, int?contactId) { if (id == null && contactId != null) // Create { Contact contact = GetUserContact(contactId.Value); if (contact != null) { return(View(new PhoneCreateEditViewModel() { Contact = contact })); } } if (id > 0) // Edit { Phone phone = phoneRepo.GetById(id.Value); if (phone != null && CheckIfContactsUserIsLogged(phone)) { PhoneCreateEditViewModel p = new PhoneCreateEditViewModel() { Id = phone.Id, Contact = phone.Contact, ContactID = phone.ContactID, PhoneNumber = phone.PhoneNumber }; return(View(p)); } } return(HttpNotFound()); }
public ActionResult CreateEdit(PhoneCreateEditViewModel model) { Contact contact = GetUserContact(model.ContactID); if (contact == null) { return(HttpNotFound()); } model.Contact = contact; if (!ModelState.IsValid) { return(View(model)); } Phone phone; if (model.Id > 0) // Edit { phone = phoneRepo.GetById(model.Id); if (phone == null || phone.ContactID != model.ContactID) { return(HttpNotFound()); } } else // Create { phone = new Phone() { ContactID = model.ContactID }; } phone.PhoneNumber = model.PhoneNumber; phoneRepo.Save(phone); return(RedirectToAction("Index", new { id = phone.ContactID })); }
public ActionResult Details(int?id) //phoneID { if (id != null) { Phone phone = phoneRepo.GetById(id.Value); if (phone != null && CheckIfContactsUserIsLogged(phone)) { PhoneCreateEditViewModel p = new PhoneCreateEditViewModel() { Id = phone.Id, Contact = phone.Contact, PhoneNumber = phone.PhoneNumber }; return(View(p)); } } return(HttpNotFound()); }