public ActionResult EditContact(Contact contact) { using (var db = new BOCContext()) { var cont = db.Contacts.Where(x => x.ID == contact.ID).FirstOrDefault(); cont.Address = contact.Address; cont.Email = contact.Email; cont.Phonenumber = contact.Phonenumber; if (contact.Firstname != null) { cont.Firstname = contact.Firstname; } if (contact.Lastname != null) { cont.Lastname = contact.Lastname; } db.SaveChanges(); return(RedirectToAction("GetContact")); } }
public ActionResult DeleteContact(int ID) { using (var db = new BOCContext()) { Contact x = db.Contacts.Find(ID); db.Contacts.Remove(x); db.SaveChanges(); return(RedirectToAction("GetContact")); } }
//[HttpGet] //public ActionResult GetContact(string searchLetter) //{ // using (var db = new BOCContext()) // { // var info = db.Contacts.ToList(); // db.Contacts.Where(c => c.Firstname.Contains(searchLetter) || searchLetter == null).ToList() // return View(info); // } //} public ActionResult AddContact(Contact contact) { using (var db = new BOCContext()) { if (!ModelState.IsValid) { return(View(contact)); } db.Contacts.Add(contact); db.SaveChanges(); ModelState.Clear(); return(View()); } }