예제 #1
0
 public ActionResult EditMD(MusicalDirector director)
 {
     if (ModelState.IsValid)
     {
         repo.Save(director);
         return RedirectToAction("Index");
     }
     return View(director);
 }
예제 #2
0
 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);
        }
예제 #4
0
 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();
     }
 }