public async Task <IForecast> GetForecast(ForecastFilter filter) { IForecast forecast = null; if (!filter.ForecastId.HasValue) { throw new ArgumentNullException("ForecastId not specified"); } forecast = await Task.FromResult <IForecast>(_forecastDataStore.ForecastGet(filter.ForecastId.Value)); if (forecast == null) { throw new ArgumentException(string.Format("Forecast {0} not found", filter.ForecastId.Value)); } //await HydrateForecast(forecast); return(forecast); }
public List <WeatherDay> ParseForecast(String forecastString) { var forecast = JsonConvert.DeserializeObject <OwmForecast>(forecastString); var result = new List <WeatherDay>(); foreach (var day in forecast.list) { result.Add(new WeatherDay() { Date = DateTimeOffset.FromUnixTimeSeconds(day.dt).DateTime, Condition = OpenWeatherMapConditionParser.Parse(day.weather[0].icon), Humidity = RelativeHumidity.FromPercentage(day.main.humidity), Temperature = Temperature.FromCelsius(day.main.temp / 10), Wind = new Wind() { Direction = DirectionParser.FromDegrees(day.wind.deg), Speed = Speed.FromKilometersPerHour(day.wind.speed) } }); } return(ForecastFilter.Filter(result)); }
public async Task <PagedResults <ForecastSummary> > ListForecasts(ForecastFilter filter) { return(await Task.FromResult <PagedResults <ForecastSummary> >( _forecastDataStore.ForecastGetMany(filter))); }
public static async Task <ForecastComparisonViewModel> GetModel(IDataContext context, ForecastFilter filter) { if (filter.ForecastId.HasValue) { return(await GetFullAndPartialViewModelForForecast(context, filter)); } return(await GetFullAndPartialViewModelForForecasts(context, filter)); }
private static async Task <ForecastComparisonViewModel> GetFullAndPartialViewModelForForecasts(IDataContext context, ForecastFilter filter) { var modelBase = SharedModelBase.GetBaseModel(context); var model = new ForecastComparisonViewModel(modelBase) { PageIndex = filter.PageIndex.HasValue ? filter.PageIndex.Value : 1, PageSize = filter.PageSize.HasValue ? filter.PageSize.Value : Int32.MaxValue, Configuration = context.ConfigurationSettings }; model.Forecasts = await context.Forecast.ListForecasts(filter); return(model); }
public PagedResults <ForecastSummary> ForecastGetMany(ForecastFilter filter) { PagedResults <ForecastSummary> retVal; using (var conn = DbHelper.GetDBConnection()) { try { var para = new DynamicParameters(); var totalRecords = 0; var totalDisplayRecords = 0; if (filter.ForecastId.HasValue) { para.Add("@ForecastId", filter.ForecastId.Value, DbType.Int32); } if (!string.IsNullOrEmpty(filter.FilterMessage)) { para.Add("@FilterMessage", filter.FilterMessage, DbType.String, size: 50); } if (filter.PageIndex.HasValue) { para.Add("@PageIndex", filter.PageIndex.Value, DbType.Int32); } if (filter.PageSize.HasValue) { para.Add("@PageSize", filter.PageSize.Value, DbType.Int32); } if (filter.SortIndex.HasValue) { para.Add("@SortIndex", filter.SortIndex.Value, DbType.Int32); } if (filter.SortDirection != Model.Enumerations.SortDirection.NotSet) { var direction = filter.SortDirection == Model.Enumerations.SortDirection.Descending ? "DESC" : "ASC"; para.Add("@SortDirection", direction, DbType.String); } // TODO implement the CDSId to get only those forecasts the user has permissions for para.Add("@CDSId", CurrentCDSID, DbType.String); para.Add("@TotalPages", dbType: DbType.Int32, direction: ParameterDirection.Output); para.Add("@TotalRecords", dbType: DbType.Int32, direction: ParameterDirection.Output); para.Add("@TotalDisplayRecords", dbType: DbType.Int32, direction: ParameterDirection.Output); var results = conn.Query <ForecastSummary>("dbo.Fdp_Forecast_GetMany", para, commandType: CommandType.StoredProcedure); var forecastSummaries = results as IList <ForecastSummary> ?? results.ToList(); if (forecastSummaries.Any()) { totalRecords = para.Get <int>("@TotalRecords"); totalDisplayRecords = para.Get <int>("@TotalDisplayRecords"); } retVal = new PagedResults <ForecastSummary>() { PageIndex = filter.PageIndex ?? 1, TotalRecords = totalRecords, TotalDisplayRecords = totalDisplayRecords, PageSize = filter.PageSize ?? totalRecords }; var currentPage = new List <ForecastSummary>(); foreach (var result in forecastSummaries) { currentPage.Add(result); } retVal.CurrentPage = currentPage; } catch (Exception ex) { AppHelper.LogError("ForecastDataStore.ForecastGetMany", ex.Message, CurrentCDSID); throw; } } return(retVal); }