public ActionResult EditContact(ContactModel cm) { if (!TryUpdateModel(cm)) { ViewBag.updateError = "Update Failure"; return PartialView("Edit", cm); } context.Entry(cm).State = System.Data.EntityState.Modified; context.SaveChanges(); return PartialView("PartialContacts", context.Contacts); }
public ActionResult Create(ContactModel cm) { if (ModelState.IsValid) { context.Contacts.Add(cm); context.SaveChanges(); return RedirectToAction("Index"); } return View(cm); }
public void Create(ContactModel contactModel) { foreach (ContactModel cm in Contacts) { if (cm.UserName == contactModel.UserName) { throw new System.InvalidOperationException("Username already exists: " + cm.UserName); } } contactList.Add(contactModel); }
public void Update(ContactModel contactModel) { foreach (ContactModel cm in Contacts) { if (cm.UserName == contactModel.UserName) { Contacts.Remove(cm); Contacts.Add(contactModel); break; } } }
public PartialViewResult MakeUpdate(ContactModel cm) { context.Entry(cm).State = System.Data.EntityState.Modified; context.SaveChanges(); return PartialView("Index"); }