Exemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            var service = CreateBandService();
            var detail  = service.GetBandById(id);
            var model   =
                new BandEdit
            {
                BandId         = detail.BandId,
                Name           = detail.Name,
                Members        = detail.Members,
                YearsActive    = detail.YearsActive,
                NumberOfAlbums = detail.NumberOfAlbums
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public bool UpdateBand(BandEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Bands
                    .Single(e => e.BandId == model.BandId && e.UserId == _userId);

                entity.Name           = model.Name;
                entity.Members        = model.Members;
                entity.YearsActive    = model.YearsActive;
                entity.NumberOfAlbums = model.NumberOfAlbums;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id, BandEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.BandId != id)
            {
                ModelState.AddModelError("", "Id Does Not Match!");
                return(View(model));
            }

            var service = CreateBandService();

            if (service.UpdateBand(model))
            {
                TempData["SaveResult"] = "Band Updated!";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Could Not Update Band!");
            return(View(model));
        }