//Get
        public ActionResult Edit(int id)
        {
            var service = new SpaceShipService();
            var detail  = service.GetSpaceShipById(id);
            var model   =
                new SpaceShipEdit
            {
                Id           = detail.Id,
                ShipName     = detail.ShipName,
                CrewCapacity = detail.CrewCapacity
            };

            return(View(model));
        }
Пример #2
0
 //update
 public bool UpdateSpaceShip(SpaceShipEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var oldData =
             ctx
             .SpaceShips
             .Single(s => s.Id == model.Id);
         oldData.Id           = model.Id;
         oldData.ShipName     = model.ShipName;
         oldData.CrewCapacity = model.CrewCapacity;
         oldData.ModifiedUtc  = DateTimeOffset.Now;
         return(ctx.SaveChanges() == 1);
     }
 }
        public ActionResult Edit(int id, SpaceShipEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.Id != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var service = new SpaceShipService();

            if (service.UpdateSpaceShip(model))
            {
                TempData["SaveResult"] = "Your ship was updated!";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Your ship could not be updated.");
            return(View(model));
        }