Exemplo n.º 1
0
        public ForecastDTO MapForecast(Forecast forecast)
        {
            ForecastDTO forecastDTO = new ForecastDTO();

            forecastDTO.MainParameters = forecast.MainParameters;

            forecastDTO.MainParameters.Temperature = Math.Round(forecastDTO.MainParameters.Temperature - 273.15);      // Get Temperature in Celsius
            forecastDTO.MainParameters.Pressure    = Math.Round(forecastDTO.MainParameters.Pressure * 0.750061561303); // hPa pressure to mmHg
            forecastDTO.MainParameters.Humidity    = Math.Round(forecastDTO.MainParameters.Humidity);

            forecastDTO.Weather = forecast.Weather[0];
            forecastDTO.Wind    = forecast.Wind;

            TimeZone localZone = TimeZone.CurrentTimeZone;

            DateTimeOffset offset = DateTimeOffset.FromUnixTimeSeconds(forecast.TimeOfForecast);

            forecastDTO.TimeOfForecast = localZone.ToLocalTime(offset.UtcDateTime);

            DateTime date = localZone.ToLocalTime(DateTime.ParseExact(forecast.DateOfCalculation, "yyyy-MM-dd HH:mm:ss",
                                                                      System.Globalization.CultureInfo.InvariantCulture));

            forecastDTO.DateOfCalculation = date;

            return(forecastDTO);
        }
Exemplo n.º 2
0
        public void SaveChangesTest()
        {
            var forecastDto = new ForecastDTO();

            forecastDto.Id = 1;
            var result = service.SaveToHistory(forecastDto).Result;

            Assert.AreEqual(0, result);
        }
Exemplo n.º 3
0
        public void StandupTest()
        {
            var forecastDTO = new ForecastDTO(true);

            //
            Assert.IsTrue(forecastDTO.CurrentBTCValue > 0D, "Current BTC Value is zero");
            //
            Utils.LoadForecastDTO(forecastDTO);
            //Assert we have some rows with data
            Assert.IsTrue(forecastDTO.GetHistoricalRow(0).OpenAmount > 0D, "Loading Forecast DTO yielded a Zero open amount.");
            //
        }
Exemplo n.º 4
0
 public ForecastDTO GetSavedForecast()
 {
     try
     {
         var         StoredForecast = sqLiteConnection.Query <ForecastDTO>("SELECT * FROM Forecast ORDER BY fID DESC");
         ForecastDTO forecast       = StoredForecast[0];
         return(forecast);
     }
     catch (Exception ex)
     {
         errorLogger.LogError("GetSavedLocationText", ex.GetType().FullName, ex.Message, "Couldn't retrieve location text. Possibly empty table", 013);
         return(new ForecastDTO());
     }
 }
Exemplo n.º 5
0
        public async Task <int> SaveToHistory(ForecastDTO forecastDto, int userId = 0)
        {
            var forecast = _mapper.Map <Forecast>(forecastDto);
            var history  = _uow.Histories.Get(userId) ?? new SearchHistory();

            history.Results.Add(forecast);
            if (history.Id == 0)
            {
                _uow.Histories.Create(history);
            }
            else
            {
                _uow.Histories.Update(history);
            }
            await _uow.SaveAsync();

            return(history.Id);
        }
Exemplo n.º 6
0
        public async Task <ActionResult> Index(SearchFormViewModel model)
        {
            try
            {
                var resultModel = new ComplexViewModel();
                resultModel.Form = model;
                ForecastDTO forecastDTO = null;
                if (ModelState.IsValid)
                {
                    forecastDTO = await WeatherService.GetWeatherDaily(model.CityName, model.ResultCount);
                }

                if (forecastDTO != null)
                {
                    var forecast = _mapper.Map <ForecastViewModel>(forecastDTO);
                    resultModel.Result = forecast;
                    var cookie = Request?.Cookies["Id"];
                    if (cookie != null)
                    {
                        await HistoryService.SaveToHistory(forecastDTO, Convert.ToInt32(cookie.Value));
                    }
                    else
                    {
                        var id = await HistoryService.SaveToHistory(forecastDTO);

                        cookie       = new HttpCookie("Id");
                        cookie.Value = id.ToString();
                        Response?.SetCookie(cookie);
                    }
                    return(View(resultModel));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 7
0
        public void SaveNewForecast(ForecastResponse forecast)
        {
            ForecastDTO forecastDTO = forecast.ConvertToDTO();

            sqLiteConnection.Insert(forecastDTO);
        }
Exemplo n.º 8
0
 private void LoadLocalForecast()
 {
     localForecast = db_helper.GetSavedForecast();
 }