public ActionResult Edit(Custom_Person person) { try { var p = db.Custom_Person.First(x => x.ID == person.ID); p.FirstName = person.FirstName; p.LastName = person.LastName; db.SaveChanges(); TempData["message"] = "Person Updated Successful!"; return(RedirectToAction("Index")); } catch { TempData["message"] = "Oops there was a problem!"; return(RedirectToAction("Index")); } }
public ActionResult Delete(int id, FormCollection collection) { try { Custom_Person p = db.Custom_Person.First(x => x.ID == id); db.Custom_Person.Remove(p); db.SaveChanges(); TempData["message"] = "Person Deleted Successful!"; return(RedirectToAction("Index")); } catch { ViewBag.Message = "Oops there was a problem!"; return(View()); } }
public ActionResult Create(string firstname, string lastname) { if (string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(lastname)) { TempData["message"] = "You must enter something in both fields to create a record"; return(RedirectToAction("Index")); } else { Custom_Person person = new Custom_Person { FirstName = firstname, LastName = lastname }; db.Custom_Person.Add(person); db.SaveChanges(); TempData["message"] = "Employee record created!"; return(RedirectToAction("Index")); } }