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)); }
public ActionResult MeteoData(string data) { //string data = "r:533|t:15.09|h:84.17|pt:19.43|p:983.65|g:10.60=r:470|t:15.08|h:84.22|pt:19.41|p:983.53|g:6.62=r:477|t:15.11|h:84.61|pt:19.41|p:983.61|g:21.19="; if (data != null) { HistoryCard historyCard = ParserMeteoData.ParseInCard(data); historyCard.DateTime = DateTime.Now; if (DataValidation.AllValidation(historyCard)) { db.HistoryCards.Add(historyCard); db.SaveChanges(); } } return(RedirectToAction("OpenWeatherData")); }
public void AllValidation_CorrectHistoryCard() { HistoryCard card = new HistoryCard() { Temperature = 15, Humidity = 84.33f, Pressure = 983.6f, Radiation = 12.8f, Description = "-", WindDirection = "NE", WindSpeed = 23 }; Assert.IsTrue(DataValidation.AllValidation(card)); }
public void AllValidation_ForecastCardIsNull() { ForecastCard card = null; Assert.IsFalse(DataValidation.AllValidation(card)); }
public void AllValidation_HistoryCardIsNull() { HistoryCard card = null; Assert.IsFalse(DataValidation.AllValidation(card)); }