//GET: Flight/Edit
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            Flight flight = await _context.Flights.FindAsync(id);

            if (flight == null)
            {
                return(NotFound());
            }
            FlightsEditViewModel model = new FlightsEditViewModel
            {
                LocationFrom            = flight.LocationFrom,
                LocationTo              = flight.LocationTo,
                Going                   = flight.Going,
                Return                  = flight.Return,
                TypeOfPlane             = flight.TypeOfPlane,
                PlaneID                 = flight.PlaneID,
                NameOfAviator           = flight.NameOfAviator,
                CapacityOfEconomyClass  = flight.CapacityOfEconomyClass,
                CapacityOfBusinessClass = flight.CapacityOfBusinessClass
            };

            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(string id, FlightsEditViewModel flightsEditViewModel)
        {
            if ((flightsEditViewModel.TimeOfLanding - flightsEditViewModel.TimeOfDepartment).TotalMinutes < 30)
            {
                ModelState.AddModelError(nameof(flightsEditViewModel.TimeOfLanding), "The  shortest flight is 30 minutes");
            }

            if (!ModelState.IsValid)
            {
                return(View(flightsEditViewModel));
            }

            Flight flight = await this.context.Flights.SingleOrDefaultAsync(x => x.Id == id);

            flight.StartLocation          = flightsEditViewModel.StartLocation;
            flight.FinalLocation          = flightsEditViewModel.FinalLocation;
            flight.TimeOfDepartment       = flightsEditViewModel.TimeOfDepartment;
            flight.TimeOfLanding          = flightsEditViewModel.TimeOfLanding;
            flight.PlaneType              = flightsEditViewModel.PlaneType;
            flight.PlaneNumber            = flightsEditViewModel.PlaneNumber;
            flight.PilotName              = flightsEditViewModel.PilotName;
            flight.EconomyClassCapacity   = flightsEditViewModel.EconomyClassCapacity;
            flight.BuissnessClassCapacity = flightsEditViewModel.BuissnessClassCapacity;

            this.context.Update(flight);
            await this.context.SaveChangesAsync();

            return(Redirect("/"));
        }
 public async Task <IActionResult> Edit(FlightsEditViewModel editModel)
 {
     if (ModelState.IsValid)
     {
         Flight flight = new Flight()
         {
             LocationFrom            = editModel.LocationFrom,
             LocationTo              = editModel.LocationTo,
             Going                   = editModel.Going,
             Return                  = editModel.Return,
             TypeOfPlane             = editModel.TypeOfPlane,
             NameOfAviator           = editModel.NameOfAviator,
             CapacityOfEconomyClass  = editModel.CapacityOfEconomyClass,
             CapacityOfBusinessClass = editModel.CapacityOfBusinessClass
         };
         try
         {
             _context.Update(flight);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!FlightExist(flight.PlaneID))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(editModel));
 }
Beispiel #4
0
        public async Task <IActionResult> Edit(string id)
        {
            Flight flight = await this.context.Flights.SingleOrDefaultAsync(x => x.Id == id);

            FlightsEditViewModel flightsEditViewModel = new FlightsEditViewModel()
            {
                Id                     = flight.Id,
                StartLocation          = flight.StartLocation,
                FinalLocation          = flight.FinalLocation,
                TimeOfDepartment       = flight.TimeOfDepartment,
                TimeOfLanding          = flight.TimeOfLanding,
                PlaneType              = flight.PlaneType,
                PlaneNumber            = flight.PlaneNumber,
                PilotName              = flight.PilotName,
                EconomyClassCapacity   = flight.EconomyClassCapacity,
                BuissnessClassCapacity = flight.BuissnessClassCapacity
            };

            return(View(flightsEditViewModel));
        }