public ActionResult List() { using (var dbContext = new BadHomburgDbContext()) { var personen = dbContext.Personen.ToList(); return View(personen); } }
public ActionResult Details(int id) { using (var dbContext = new BadHomburgDbContext()) { var person = dbContext.Personen.Where(p => p.Id == id).Single(); return View(person); } }
public ActionResult Create(Person person) { if (ModelState.IsValid) { using (var dbContext = new BadHomburgDbContext()) { dbContext.Personen.Add(person); dbContext.SaveChanges(); return RedirectToAction("Details", new {person.Id}); } } return View(person); }
public ActionResult Edit(int id, Person person) { if (ModelState.IsValid) { using (var dbContext = new BadHomburgDbContext()) { var oldPerson = dbContext.Personen.Single(p => p.Id == id); oldPerson.CopyFrom(person); dbContext.SaveChanges(); return RedirectToAction("Details", new { id }); } } return View(person); }