Пример #1
0
        public ActionResult Edit(int id)
        {
            var service = CreateRiderService();
            var detail  = service.GetRiderById(id);
            var model   =
                new RiderEdit
            {
                RiderId     = detail.RiderId,
                FirstName   = detail.FirstName,
                LastName    = detail.LastName,
                Destination = detail.Destination
            };

            return(View(model));
        }
Пример #2
0
        public bool UpdateRider(RiderEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Riders
                    .Single(e => e.RiderId == model.RiderId && e.OwnerId == _userId);

                entity.FirstName   = model.FirstName;
                entity.LastName    = model.LastName;
                entity.Destination = model.Destination;

                return(ctx.SaveChanges() == 1);
            }
        }
Пример #3
0
        public ActionResult Edit(int id, RiderEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateRiderService();

            if (service.UpdateRider(model))
            {
                TempData["SaveResult"] = "Your ride request has been updated!";
                return(RedirectToAction("Index"));
            }

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