Beispiel #1
0
        public async Task GetWeatherFromFavoritesList()
        {
            var list = await favoriteRepository.GetAll();

            foreach (var item in list)
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://api.openweathermap.org/data/2.5/weather?q=" + item.CityName + "&units=metric"
                                                                           + openWatherMapsApiKey);

                var    webResponse = (HttpWebResponse)request.GetResponse();
                var    reader      = new StreamReader(webResponse.GetResponseStream() ?? throw new InvalidOperationException());
                string s           = reader.ReadToEnd();
                var    json        = JsonConvert.DeserializeObject <WeatherJson>(s);
                var    weather     = Mapper.Map <WeatherJson, Weather>(json);
                weather.WindChill = Math.Round(33 + (0.478 + 0.237 * Math.Sqrt(weather.WindSpeed) - 0.0124 * weather.WindSpeed)
                                               * (weather.Temperature - 33)) * 100 / 100;
                foreach (var user in item.Id)
                {
                    WeatherHistory weatherHistory = Mapper.Map <Weather, WeatherHistory>(weather);
                    weatherHistory.Id   = user;
                    weatherHistory.Date = DateTime.Now;
                    await weatherHistoryRepository.Add(weatherHistory);

                    await weatherHistoryRepository.Save();
                }
            }
        }
 public async Task <IActionResult> RemoveFavorite(int id)
 {
     try
     {
         var authorize = Barayand.Common.Services.TokenService.AuthorizeUser(Request);
         if (authorize < 1)
         {
             return(new JsonResult(ResponseModel.Error("Your login token has expired.")));
         }
         var Favs = ((List <FavoriteModel>)(await _favoritrepostory.GetAll()).Data).FirstOrDefault(x => x.F_UserId == authorize && x.F_EntityId == id);
         if (Favs == null)
         {
             return(new JsonResult(ResponseModel.Error("Your login token has expired.")));
         }
         return(new JsonResult(await _favoritrepostory.Delete(Favs)));
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Beispiel #3
0
 public IEnumerable <FavoriteEntity> GetAll()
 {
     return(favoriteRepository.GetAll().Select(x => x.ToBllFavorite()));
 }