コード例 #1
0
        public ActionResult Edit(int id)
        {
            var service = CreateTransportService();
            var detail  = service.GetTransportById(id);
            var model   =
                new TransportEdit
            {
                TransportId       = detail.TransportId,
                Type              = detail.Type,
                Departure         = detail.Departure,
                ReservationNumber = detail.ReservationNumber
            };

            return(View(model));
        }
コード例 #2
0
        public bool UpdateTransport(TransportEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Transports
                    .Single(e => e.TransportId == model.TransportId);

                entity.TransportId       = model.TransportId;
                entity.Type              = model.Type;
                entity.Departure         = model.Departure;
                entity.ReservationNumber = model.ReservationNumber;

                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #3
0
        public ActionResult Edit(int id, TransportEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.TransportId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateTransportService();

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

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