public async Task <IActionResult> Edit(EditFlightViewModel model) { IActionResult result; if (ModelState.IsValid) { DateTime start = CombineDateAndTime(model.StartDate, model.StartTime); DateTime end = CombineDateAndTime(model.EndDate, model.EndTime); Flight flight = await _flights.UpdateFlightAsync( model.Id, model.DroneId, model.LocationId, model.OperatorId, start, end); // Redirect to the flight details/properties page result = RedirectToAction("Index", "FlightDetails", new { id = flight.Id }); } else { // If the model state isn't valid, load the lists of drones, // locations and operators and redisplay the flight logging page List <Drone> drones = await _drones.GetDronesAsync(); List <Location> locations = await _locations.GetLocationsAsync(); List <Operator> operators = await _operators.GetOperatorsAsync(); model.SetDrones(drones); model.SetLocations(locations); model.SetOperators(operators); result = View(model); } return(result); }
public async Task <IActionResult> Edit(int id) { List <Drone> drones = await _drones.GetDronesAsync(); List <Location> locations = await _locations.GetLocationsAsync(); List <Operator> operators = await _operators.GetOperatorsAsync(); Flight flight = await _flights.GetFlightAsync(id); EditFlightViewModel model = _mapper.Map <EditFlightViewModel>(flight); model.SetDrones(drones); model.SetLocations(locations); model.SetOperators(operators); model.StartDate = model.Start.ToString("MM/dd/yyyy"); model.StartTime = model.Start.ToString("HH:mm"); model.EndDate = model.End.ToString("MM/dd/yyyy"); model.EndTime = model.Start.ToString("HH:mm"); return(View(model)); }