public Forecast Fetch() { var doc = XDocument.Load(string.Format(FORECAST_URL, _zip)); var forecastDays = new List<ForecastDay>(); foreach(var day in doc.Descendants("simpleforecast").Descendants("forecastday")) { var forecastDay = new ForecastDay { Period = Convert.ToInt32(day.Element("period").Value), Date = day.Element("date").Element("pretty").Value, Conditions = day.Element("conditions").Value, High = day.Element("high").Element("fahrenheit").Value, Low = day.Element("low").Element("fahrenheit").Value, IconURL = day.Descendants("icon_set") .Where(i => i.Attribute("name").Value == "Default") .Elements("icon_url").First().Value }; forecastDays.Add(forecastDay); } return new Forecast { Location = _zip, Days = forecastDays.ToArray() }; }
public ForecastViewModel(ForecastDay day) { if (day == null) throw new ArgumentNullException(); this.High_F = day.high.fahrenheit; this.High_C = day.high.celsius; this.Low_F = day.low.fahrenheit; this.Low_C = day.low.celsius; this.Weekday = day.date.weekday.ToLower(); this.DayNumber = day.date.day; this.Condition = day.conditions.ToLower(); }
public ForecastViewModel(ForecastDay day) { if (day == null) { throw new ArgumentNullException(); } this.High_F = day.high.fahrenheit; this.High_C = day.high.celsius; this.Low_F = day.low.fahrenheit; this.Low_C = day.low.celsius; this.Weekday = day.date.weekday.ToLower(); this.DayNumber = day.date.day; this.Condition = day.conditions.ToLower(); }