public ActionResult EditMD(MusicalDirector director) { if (ModelState.IsValid) { repo.Save(director); return RedirectToAction("Index"); } return View(director); }
public ActionResult EditMD() { MusicalDirector director = repo.GetDirector(); if (director == null) { director = new MusicalDirector(); } return View(director); }
public void Save_New_MD_Creates_It() { IMemberRepository repo = Substitute.For<IMemberRepository>(); repo.GetDirector().Returns(d => null); MembersController controller = new MembersController(repo); MusicalDirector director = new MusicalDirector {Name = "Fred", Description = "Fred's Description"}; var result = controller.EditMD(director); repo.Received().Save(director); }
public void Save(MusicalDirector director) { using (DbContext context = new DbContext()) { if (context.MusicalDirectors.Any()) { context.Entry(director).State = EntityState.Modified; } else { context.MusicalDirectors.Add(director); } context.SaveChanges(); } }