//Get
        public ActionResult Edit(int id)
        {
            var service = new SpaceStationService();
            var detail  = service.GetSpaceStationById(id);
            var model   =
                new SpaceStationEdit
            {
                Id               = detail.Id,
                Name             = detail.Name,
                MaximumOccupancy = detail.MaximumOccupancy
            };

            return(View(model));
        }
Ejemplo n.º 2
0
 //update
 //test
 public bool UpdateSpaceStation(SpaceStationEdit newStationData)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var oldData =
             ctx
             .SpaceStations
             .Single(s => s.Id == newStationData.Id);
         oldData.Id               = newStationData.Id;
         oldData.Name             = newStationData.Name;
         oldData.MaximumOccupancy = newStationData.MaximumOccupancy;
         oldData.ModifiedUtc      = DateTimeOffset.Now;
         return(ctx.SaveChanges() == 1);
     }
 }
        public ActionResult Edit(int id, SpaceStationEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.Id != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var service = new SpaceStationService();

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