예제 #1
0
        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"));
            }
        }
예제 #2
0
 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"));
     }
 }
예제 #3
0
        //[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());
            }
        }