예제 #1
0
 public ActionResult EditContact(int id)
 {
     using (var db = new BOCContext())
     {
         return(View(db.Contacts.Where(x => x.ID == id).FirstOrDefault()));
     }
 }
예제 #2
0
 public ActionResult GetContact(string search, string searchBy)
 {
     using (var db = new BOCContext())
     {
         if (searchBy == "Firstname")
         {
             return(View(db.Contacts.Where(c => c.Firstname.StartsWith(search) || search == null).ToList()));
         }
         else if (searchBy == "Lastname")
         {
             return(View(db.Contacts.Where(c => c.Lastname.StartsWith(search) || search == null).ToList()));
         }
         else if (searchBy == "Phonenumber")
         {
             return(View(db.Contacts.Where(c => c.Phonenumber.StartsWith(search) || search == null).ToList()));
         }
         else if (searchBy == "Email")
         {
             return(View(db.Contacts.Where(c => c.Email.StartsWith(search) || search == null).ToList()));
         }
         else
         {
             return(View(db.Contacts.Where(c => c.Address.StartsWith(search) || search == null).ToList()));
         }
     }
 }
예제 #3
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"));
            }
        }
예제 #4
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"));
     }
 }
예제 #5
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());
            }
        }