public ActionResult Delete(int?id) { if (id != null) { using (var db = new persondemoEntities(GetCnString())) { var person = new Person() { ID = id.Value }; db.People.Attach(person); db.People.Remove(person); db.SaveChanges(); } } return(View("Index", GetPeople())); }
public ActionResult Add(PersonViewModel model) { string cnString = GetCnString(); using (var db = new persondemoEntities(cnString)) { db.People.Add(new Person() { LastName = model.NewPerson.LastName, FirstName = model.NewPerson.FirstName, Sport = model.NewPerson.Sport }); db.SaveChanges(); } ModelState.Clear(); return(View("Index", GetPeople())); }