Exemplo n.º 1
0
        /// <summary>
        /// Construct the model to confirm sighting details
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public async Task <ConfirmDetailsViewModel> GetConfirmDetailsModelAsync(string userName)
        {
            // Get the sighting, flight details and aircraft models and map them
            // into the confirm details model
            ConfirmDetailsViewModel model = new ConfirmDetailsViewModel();

            string key = GetCacheKey(SightingDetailsKeyPrefix, userName);
            SightingDetailsViewModel sighting = _cache.Get <SightingDetailsViewModel>(key);

            _mapper.Map <SightingDetailsViewModel, ConfirmDetailsViewModel>(sighting, model);

            key = GetCacheKey(FlightDetailsKeyPrefix, userName);
            FlightDetailsViewModel flight = _cache.Get <FlightDetailsViewModel>(key);

            _mapper.Map <FlightDetailsViewModel, ConfirmDetailsViewModel>(flight, model);

            key = GetCacheKey(AircraftDetailsKeyPrefix, userName);
            AircraftDetailsViewModel aircraft = _cache.Get <AircraftDetailsViewModel>(key);

            _mapper.Map <AircraftDetailsViewModel, ConfirmDetailsViewModel>(aircraft, model);

            // For the location, if we have a new location specified then use that as the
            // location. Otherwise, look up the location by its ID
            if (sighting.LocationId == 0)
            {
                model.Location = sighting.NewLocation;
            }
            else
            {
                Location location = await _locations.GetLocationAsync(sighting.LocationId);

                model.Location = location.Name;
            }

            // Repeat the above logic for the airline
            if (flight.AirlineId == 0)
            {
                model.Airline = flight.NewAirline;
            }
            else
            {
                Airline airline = await _airlines.GetAirlineAsync(flight.AirlineId);

                model.Airline = airline.Name;
            }

            // Repeat the above logic for the manufacturer
            if ((aircraft.ManufacturerId ?? 0) == 0)
            {
                model.Manufacturer = aircraft.NewManufacturer;
            }
            else
            {
                int          manufacturerId = aircraft.ManufacturerId ?? 0;
                Manufacturer manufacturer   = await _manufacturers.GetManufacturerAsync(manufacturerId);

                model.Manufacturer = manufacturer.Name;
            }

            // Repeat the above logic for the model
            if ((aircraft.ModelId ?? 0) == 0)
            {
                model.Model = aircraft.NewModel;
            }
            else
            {
                int   modelId       = aircraft.ModelId ?? 0;
                Model aircraftModel = await _models.GetModelAsync(modelId);

                model.Model = aircraftModel.Name;
            }

            return(model);
        }
        public async Task <IActionResult> Edit(int id)
        {
            Airline model = await _client.GetAirlineAsync(id);

            return(View(model));
        }