public UpsertFlightViewModel Create(int flightId) { var airports = _airportsListQuery.Execute(); var aircrafts = _aircraftListQuery.Execute(); var flight = _flightQuery.Execute(flightId); var viewModel = new UpsertFlightViewModel(); viewModel.Airports = airports .Select(a => new SelectListItem() { Value = a.Id.ToString(), Text = $"{a.IATA} - {a.City}", }) .ToList(); viewModel.Aircrafts = aircrafts .Select(a => new SelectListItem() { Value = a.Id.ToString(), Text = a.ModelName, }) .ToList(); viewModel.Flight = new CreateFlightModel() { DepartureAirportId = flight.DepartureAirportId, DestinationAirportId = flight.DestinationAirportId, AircraftId = flight.AircraftId }; return(viewModel); }
public UpsertFlightViewModel Create() { var airports = _airportsListQuery.Execute(); var aircrafts = _aircraftListQuery.Execute(); var viewModel = new UpsertFlightViewModel(); viewModel.Airports = airports .Select(a => new SelectListItem() { Value = a.Id.ToString(), Text = $"{a.IATA} - {a.City}", }) .ToList(); viewModel.Aircrafts = aircrafts .Select(a => new SelectListItem() { Value = a.Id.ToString(), Text = a.ModelName, }) .ToList(); viewModel.Flight = new CreateFlightModel(); return(viewModel); }
public ActionResult Create(UpsertFlightViewModel viewModel) { try { _createFlightCommand.Execute(viewModel.Flight); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(View()); } }
public ActionResult Edit(int id, UpsertFlightViewModel viewModel) { try { var updateModel = new UpdateFlightModel { FlightId = id, Flight = viewModel.Flight }; _updateFlightCommand.Execute(updateModel); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }