示例#1
0
        public IActionResult GetCitiesForMonth(Guid monthId)
        {
            if (!_monthRepository.EntityExists(monthId))
            {
                return(NotFound());
            }

            var citiesForMonthFromRepo = _monthRepository.GetCitiesForMonth(monthId);
            var results = Mapper.Map <IEnumerable <CityApiModel> >(citiesForMonthFromRepo);

            return(Ok(results));
        }
示例#2
0
        public IActionResult GetMonths()
        {
            var monthsFromRepo = _monthRepository.GetMonths();


            var monthsApiModel = Mapper.Map <IEnumerable <MonthApiModel> >(monthsFromRepo);


            foreach (var monthApiModel in monthsApiModel)
            {
                var citiesFromRepo = _monthRepository.GetCitiesForMonth(monthApiModel.Id).Take(5);

                foreach (var city in citiesFromRepo)
                {
                    var cityApiModel = Mapper.Map <CityApiModel>(city);

                    cityApiModel.MainImageId = _imageRepository.GetMainImageIdForCity(city.Id);

                    monthApiModel.TopCities.Add(cityApiModel);
                }
            }

            return(Ok(monthsApiModel));
        }