public async Task <IActionResult> Index(AccountsQuery query, CancellationToken cancellationToken) { var queryable = MailAppDbContext.Accounts .Where(x => String.IsNullOrEmpty(query.Nick) || x.Nick.Contains(query.Nick)) .Where(x => String.IsNullOrEmpty(query.Email) || x.Email.Contains(query.Email)); queryable = query.Sort switch { AccountsQuery.SortingOptions.Email => queryable.OrderBy(x => x.Email), AccountsQuery.SortingOptions.Nick => queryable.OrderBy(x => x.Nick), _ => queryable }; var accounts = await queryable .Select(x => new AccountViewModel(x)) .ToArrayAsync(cancellationToken); var viewModel = new AccountsListViewModel { Email = query.Email, Nick = query.Nick, Accounts = accounts }; return(View("List", viewModel)); } }
public AccountsQueryTests() { fakeDbContext = A.Fake <DFCUserAccountsContext>(); repo = new AccountsQuery(this.fakeDbContext); testAuditTable = new List <Audit>(); var fakeAuditDbSet = Aef.FakeDbSet(this.testAuditTable); A.CallTo(() => fakeDbContext.Audit).Returns(fakeAuditDbSet); }
public IActionResult GetPreferences([FromQuery] AccountsQueryRequest parameters) { if (!ModelState.IsValid) { return(BadRequest()); } AccountsQuery request = _mapper.Map <AccountsQuery>(parameters); return(Ok(request)); }
public async Task <ActionResult> GetAccounts([FromQuery] AccountsQuery accountsQuery) { var accountQueryResponse = await _accountService.GetAccounts(accountsQuery.Page, accountsQuery.PerPage, accountsQuery.Filter); var selectedAccountData = _accountPropertySelector.SelectPropertiesToReturn(accountQueryResponse.Accounts, accountsQuery.Fields, accountsQuery.IncludeFields); if (accountsQuery.IncludeTotals) { var response = _accountPropertySelector.IncludeTotalsInResult(selectedAccountData, accountQueryResponse.TotalCount, accountsQuery.Page, accountsQuery.PerPage); return(Ok(response)); } return(Ok(selectedAccountData)); }
public IReadOnlyCollection <Account> GetAccounts(Guid userId) { var query = new AccountsQuery(dbContext.Accounts); return(new AccountMapper().Map(query.Execute(userId)).ToList()); }
AccountsQuery BuildBankAccountsQuery(IEnumerable <Customer> customers) => AccountsQuery.Create(customers.Select(c => c.Id));