public ActionResult Edit(int id)
        {
            var           service = CreateConcertService();
            ConcertDetail detail  = service.GetConcertById(id);
            var           model   =
                new ConcertEdit
            {
                ConcertId = detail.ConcertId,
                Artist    = detail.Artist,
                TourName  = detail.TourName,
                City      = detail.City,
                State     = detail.State,
                Price     = detail.Price,
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public bool UpdateConcert(ConcertEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Concerts
                    .Single(e => e.ConcertId == model.ConcertId);

                entity.Artist   = model.Artist;
                entity.TourName = model.TourName;
                entity.City     = model.City;
                entity.State    = model.State;
                entity.Price    = model.Price;
                entity.Date     = model.Date;

                entity.ModifiedUtc = DateTimeOffset.UtcNow;
                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Edit(int id, ConcertEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.ConcertId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var service = CreateConcertService();

            if (service.UpdateConcert(model))
            {
                TempData["SaveResult"] = "Your Concert Tour was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your Concert Tour could not be updated.");
            return(View(model));
        }