示例#1
0
 public ActionResult Create(Contact contact)
 {
     try
     {
         // TODO: Add insert logic here
         if (ModelState.IsValid) {
             _repo.Add<Contact>(contact);
             _repo.SaveChanges();
             return RedirectToAction("Index");
         }
         return View();
     }
     catch
     {
         return View();
     }
 }
示例#2
0
        public ActionResult Edit(int id, Contact contact)
        {
            try
            {
                // TODO: Add update logic here

                Contact newContact = _repo.Find<Contact>(id);
                newContact.Id = contact.Id;
                newContact.FirstName = contact.FirstName;
                newContact.LastName = contact.LastName;
                newContact.Birthday = contact.Birthday;
                newContact.PhoneNumber = contact.PhoneNumber;
                _repo.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }