コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public ActionResult Create(UpsertFlightViewModel viewModel)
 {
     try
     {
         _createFlightCommand.Execute(viewModel.Flight);
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception ex)
     {
         return(View());
     }
 }
コード例 #4
0
        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());
            }
        }