Пример #1
0
        public async Task <List <CityForReturnDto> > GetListAsync()
        {
            var buildingsAgeList = await cityDal.GetListAsync();

            if (buildingsAgeList == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound });
            }

            var mapForReturn = mapper.Map <List <City>, List <CityForReturnDto> >(buildingsAgeList);

            return(mapForReturn);
        }
        //[SecuredOperation("Sudo,WheatherForeCast.List", Priority = 1)]
        public async Task <List <WheatherForeCastForReturnDto> > WheatherForeCastsAsync()
        {
            var apiKey         = config.GetValue <string>("OpenAPiKey");
            var selectedCities = await cityDal.GetListAsync(x => x.Selected == true);

            var citiesId = selectedCities.Select(x => x.CityId).ToArray();
            var cityId   = string.Join(",", citiesId);

            using (HttpClient client = new HttpClient())
            {
                var httResponse = await client.GetAsync($"https://api.openweathermap.org/data/2.5/group?id={cityId}&units=metric&appid={apiKey}");

                if (!httResponse.IsSuccessStatusCode)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = "Hava durumu bilgileri alınamadı.." });
                }

                var content = await httResponse.Content.ReadAsStringAsync();

                var result       = JsonConvert.DeserializeObject <WheatherForeCast>(content);
                var mapForReturn = mapper.Map <List <WheatherForeCastHttpResponseDto>, List <WheatherForeCastForReturnDto> >(result.list);
                return(mapForReturn);
            }
        }