public async Task <ActionResult> Index(CountdownListViewModel model) { CountdownSubFilter subFilter = CreateCountdownSubFilter(model.Filter); Task <int> count = _countdownRepository.GetTotalCountAsync(subFilter); Task <IEnumerable <CountdownAggregate> > aggregates = _countdownRepository.GetAggregatesAsync(new CountdownFilter { Page = model.Page, Limit = CountdownLimit, CurrentUserAccountId = _contextService.CurrentUserAccountId, DisplayOrderType = model.DisplayOrderType, SubFilter = subFilter }); await Task.WhenAll(count, aggregates); var result = new CountdownListViewModel { Total = await count, Countdowns = (await aggregates).ToCountdownViewModels(), Page = model.Page, DisplayOrderType = model.DisplayOrderType, Filter = model.Filter, Token = model.Token }; return(Json(result, JsonRequestBehavior.AllowGet)); }
public async Task <int> GetTotalCountAsync(CountdownSubFilter subFilter) { using (IDbConnection connection = Connection) { const string sql = @"SELECT COUNT(Id) FROM Countdowns WHERE EndsOn >= ISNULL(@EndsAfter, EndsOn) AND CreatedByAccountId = ISNULL(@CreatedByUserAccountId, CreatedByAccountId) AND Description LIKE @query"; return(await connection.ExecuteScalarAsync <int>(sql, new { subFilter.EndsAfter, subFilter.CreatedByUserAccountId, query = $"%{subFilter.Query}%" })); } }
public Task <int> GetTotalCountAsync(CountdownSubFilter subFilter) { return(Task.Run(() => CountdownAggregates.Count)); }