public ActionResult Edit(int id) { using (var db = new ContactEntities()) { return View(db.Contacts.Find(id)); } }
public ActionResult Delete(int id, Contact contact) { try { using (var db = new ContactEntities()) { db.Entry(db.Contacts.Find(id)).State = EntityState.Deleted; db.SaveChanges(); return RedirectToAction("Index"); } } catch { return View(); } }
public ActionResult Create(Contact contact) { try { using (var db = new ContactEntities()) { contact.Text = HttpUtility.UrlDecode(contact.Text, System.Text.Encoding.Default); db.Contacts.Add(contact); db.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(int id, Contact contact) { try { using (var db = new ContactEntities()) { contact.Text = HttpUtility.UrlDecode(contact.Text, System.Text.Encoding.Default); db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } } catch { return View(); } }
public ActionResult Index() { using (var db = new ContactEntities()) { return View(db.Contacts.ToList()); } }
public ActionResult GetContacts() { using (var db = new ContactEntities()) { return View(db.Contacts .OrderBy(contact => contact.DisplayOrder) .ToList()); } }