示例#1
0
        // UPDATE
        public IActionResult Edit(int id)
        {
            if (User.IsInRole("Admin") == false)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var planeModel = _planes.GetById(id);

            var formData = new PlaneFormModel
            {
                Id           = id,
                MaxCapacity  = planeModel.MaxCapacity,
                Identifier   = planeModel.Identifier,
                Type         = planeModel.Type,
                Manufacturer = planeModel.Manufacturer,
                Model        = planeModel.Model,
                Year         = planeModel.Year,
                FlyingHours  = planeModel.FlyingHours
            };

            return(View(formData));
        }
示例#2
0
        public IActionResult Update(PlaneFormModel planeToBeUpdated)
        {
            if (User.IsInRole("Admin") == false)
            {
                return(RedirectToAction("Index", "Home"));
            }
            Plane _plane   = _planes.GetById(planeToBeUpdated.Id);
            Plane newPlane = new Plane
            {
                Id           = planeToBeUpdated.Id,
                Identifier   = planeToBeUpdated.Identifier,
                MaxCapacity  = planeToBeUpdated.MaxCapacity,
                Type         = planeToBeUpdated.Type,
                Manufacturer = planeToBeUpdated.Manufacturer,
                Model        = planeToBeUpdated.Model,
                Year         = planeToBeUpdated.Year,
                FlyingHours  = planeToBeUpdated.FlyingHours,
            };

            _planes.Update(_plane.Id, newPlane);
            return(RedirectToAction("Index", "Plane"));
        }