Ejemplo n.º 1
0
 public ActionResult EditBand(Band band)
 {
     if (ModelState.IsValid)
     {
         repo.Save(band);
         return RedirectToAction("Index");
     }
     return View(band);
 }
Ejemplo n.º 2
0
 public ActionResult EditBand()
 {
     Band band = repo.GetBand();
     if (band == null)
     {
         band = new Band();
     }
     return View(band);
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);

        }
Ejemplo n.º 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();
     }
 }