public static bool UpdateData(CardContext db, List <ForecastCard> forecastCards)
 {
     foreach (var card in forecastCards)
     {
         if (DataValidation.AllValidation(card))
         {
             ForecastCard forecastCard = db.ForecastCards.FirstOrDefault(x => x.DateTime == card.DateTime);
             if (forecastCard == null)
             {
                 db.ForecastCards.Add(card);
             }
             else
             {
                 forecastCard.Description     = card.Description;
                 forecastCard.Humidity        = card.Humidity;
                 forecastCard.Temperature     = card.Temperature;
                 forecastCard.WindDirection   = card.WindDirection;
                 db.Entry(forecastCard).State = EntityState.Modified;
             }
         }
     }
     try
     {
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex) {
         return(false);
     };
 }
 public void AllValidation_CorrectForecastCard()
 {
     ForecastCard card = new ForecastCard()
     {
         Temperature = 15,
         Humidity = 84.33f,
         Description = "-",
         WindDirection = "NE"
     };
     Assert.IsTrue(DataValidation.AllValidation(card));
 }
Esempio n. 3
0
        public void AllValidation_CorrectForecastCard()
        {
            ForecastCard card = new ForecastCard()
            {
                Temperature   = 15,
                Humidity      = 84.33f,
                Description   = "-",
                WindDirection = "NE"
            };

            Assert.IsTrue(DataValidation.AllValidation(card));
        }
 public static bool AllValidation(ForecastCard forecastCard)
 {
     if (forecastCard == null)
         return false;
     if (TemperatureValidation(forecastCard.Temperature) &&
         HumidityValidation(forecastCard.Humidity) &&
         WindDirectionValidation(forecastCard.WindDirection) &&
         DescriptionValidation(forecastCard.Description))
         return true;
     else
         return false;
 }
        public List <ForecastCard> ToCard()
        {
            List <ForecastCard> forecastCards = new List <ForecastCard>();

            foreach (var weather in this.ListWeather)
            {
                ForecastCard card = new ForecastCard();
                card.DateTime = Convert.ToDateTime(weather.DateTime.Replace("-", "."));
                weather.Main.KelvinToCelsius();
                card.Temperature   = (int)Convert.ToSingle(weather.Main.Temperature, new CultureInfo("en-US"));
                card.Humidity      = Convert.ToSingle(weather.Main.Humidity, new CultureInfo("en-US"));
                card.WindDirection = weather.Wind.DegreeToCardinal();
                card.Description   = weather.Weather[0].Description;
                forecastCards.Add(card);
            }
            return(forecastCards);
        }
 public static bool AllValidation(ForecastCard forecastCard)
 {
     if (forecastCard == null)
     {
         return(false);
     }
     if (TemperatureValidation(forecastCard.Temperature) &&
         HumidityValidation(forecastCard.Humidity) &&
         WindDirectionValidation(forecastCard.WindDirection) &&
         DescriptionValidation(forecastCard.Description))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
 public List<ForecastCard> ToCard()
 {
     List<ForecastCard> forecastCards = new List<ForecastCard>();
     foreach (var weather in this.ListWeather)
     {
         ForecastCard card=new ForecastCard();
         card.DateTime = Convert.ToDateTime(weather.DateTime.Replace("-","."));
         weather.Main.KelvinToCelsius();
         card.Temperature = (int)Convert.ToSingle(weather.Main.Temperature, new CultureInfo("en-US"));
         card.Humidity = Convert.ToSingle(weather.Main.Humidity, new CultureInfo("en-US"));
         card.WindDirection = weather.Wind.DegreeToCardinal();
         card.Description = weather.Weather[0].Description;
         forecastCards.Add(card);
     }
     return forecastCards;
 }
Esempio n. 8
0
        public void AllValidation_ForecastCardIsNull()
        {
            ForecastCard card = null;

            Assert.IsFalse(DataValidation.AllValidation(card));
        }