Пример #1
0
 public ActionResult EditBand(Band band)
 {
     if (ModelState.IsValid)
     {
         repo.Save(band);
         return RedirectToAction("Index");
     }
     return View(band);
 }
Пример #2
0
 public ActionResult EditBand()
 {
     Band band = repo.GetBand();
     if (band == null)
     {
         band = new Band();
     }
     return View(band);
 }
        public void Save_New_Band_Creates_It()
        {
            IMemberRepository repo = Substitute.For<IMemberRepository>();
            repo.GetBand().Returns(d => null);
            MembersController controller = new MembersController(repo);

            Band band = new Band();

            var result = controller.EditBand(band);

            repo.Received().Save(band);
        }
        public void Save_Existing_Band_Updates_It()
        {
            IMemberRepository repo = Substitute.For<IMemberRepository>();
            repo.GetBand().Returns(new Band { Id = 1 });
            MembersController controller = new MembersController(repo);

            Band band = new Band();

            var result = controller.EditBand(band);

            repo.Received().Save(band);

        }
Пример #5
0
 public void Save(Band band)
 {
     using (DbContext context = new DbContext())
     {
         if (context.Bands.Any())
         {
             context.Entry(band).State = EntityState.Modified;
         }
         else
         {
             context.Bands.Add(band);
         }
         context.SaveChanges();
     }
 }