Example #1
0
 public ActionResult Edit(int id)
 {
     using (var db = new ContactEntities())
     {
         return View(db.Contacts.Find(id));
     }
 }
Example #2
0
 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();
     }
 }
Example #3
0
 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();
     }
 }
Example #4
0
 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();
     }
 }
Example #5
0
 public ActionResult Index()
 {
     using (var db = new ContactEntities())
     {
         return View(db.Contacts.ToList());
     }
 }
Example #6
0
 public ActionResult GetContacts()
 {
     using (var db = new ContactEntities())
     {
         return View(db.Contacts
             .OrderBy(contact => contact.DisplayOrder)
             .ToList());
     }
 }