public Task <FilterResultModel <AccountViewModel> > Handle(GetAccountsListQuery request, CancellationToken cancellationToken) { var sortBy = request.SortBy.Trim() != "" ? request.SortBy : "AccountName"; var sortDirection = (request.SortDirection.ToUpper() == "DESCENDING") ? true : false; FilterResultModel <AccountViewModel> result = new FilterResultModel <AccountViewModel> (); var accountList = _database.Accounts .Where(a => a.Year == request.Year) .Select(AccountViewModel.Projection) .Select(DynamicQueryHelper.GenerateSelectedColumns <AccountViewModel> (request.SelectedColumns)) .AsQueryable(); if (request.Filter.Count() > 0) { accountList = accountList .Where(DynamicQueryHelper .BuildWhere <AccountViewModel> (request.Filter)).AsQueryable(); } result.Count = accountList.Count(); var PageSize = (request.PageSize == 0) ? result.Count : request.PageSize; var PageNumber = (request.PageSize == 0) ? 1 : request.PageNumber; result.Items = accountList.OrderBy(sortBy, sortDirection) .Skip(PageNumber - 1) .Take(PageSize) .ToList(); return(Task.FromResult <FilterResultModel <AccountViewModel> > (result)); }
public async Task ReturnListOfAccountsSuccessfuly() { // Arrange GetAccountsListQuery query = new GetAccountsListQuery(); // Act var result = await handler.Handle(query, CancellationToken.None); // Assert Assert.IsType <FilterResultModel <AccountViewModel> > (result); }
public async Task <List <AccountDTO> > Handle(GetAccountsListQuery request, CancellationToken cancellationToken) { return(_mapper.Map <List <AccountDTO> >(await _repository.GetAll())); }
public async Task <ActionResult <FilterResultModel <AccountViewModel> > > GetAccountsList([FromBody] GetAccountsListQuery query) { var result = await _Mediator.Send(query); return(Ok(result)); }
public async Task <IActionResult> GetAll([FromQuery] GetAccountsListQuery query) { return(await Execute(query)); }