コード例 #1
0
        public ActionResult Index()
        {
            var countryInfoList     = _countriesRepository.GetCountries();
            var countryDropdownList = new List <SelectListItem>();

            if (countryInfoList != null)
            {
                foreach (var country in countryInfoList)
                {
                    countryDropdownList.Add(new SelectListItem()
                    {
                        Text = country.name, Value = country.code
                    });
                }
            }

            CountryModel countryModel = new CountryModel
            {
                countryInfo          = countryInfoList,
                countryDropdownItems = countryDropdownList
            };

            var selectedCountryCode = _countriesRepository.GetCountries()?.First()?.code;
            var cityInfoList        = _citiesRepository.GetCitiesRequest(selectedCountryCode);
            var cityDropdownList    = new List <SelectListItem>();

            if (cityInfoList != null)
            {
                foreach (var city in cityInfoList)
                {
                    cityDropdownList.Add(new SelectListItem()
                    {
                        Text = city.city, Value = city.city
                    });
                }
            }

            CityModel cityModel = new CityModel
            {
                cityInfo          = cityInfoList,
                cityDropdownItems = cityDropdownList
            };

            var selectedCityName     = cityInfoList.FirstOrDefault().city;
            var measurementsInfoList = _measurementsRepository.GetMeasurementsRequest(selectedCityName);
            var measurementsDTOList  = MeasurementsMapper.MapMeasurements(measurementsInfoList);

            MeasurementsDTOModel measurementsDTOModel = new MeasurementsDTOModel
            {
                measurementsDTO = measurementsDTOList
            };

            AreaSelectionViewModel areaSelectionViewModel = new AreaSelectionViewModel()
            {
                countryModel         = countryModel,
                cityModel            = cityModel,
                measurementsDTOModel = measurementsDTOModel
            };

            return(View(areaSelectionViewModel));
        }