public async Task <Account> GetByUsernameAsync(Username username, CancellationToken cancellationToken) { Account?account = await _appDbContext.Set <Account>() .Where(acc => acc.Username.Value == username.Value) .FirstOrDefaultAsync(cancellationToken); if (account == null) { throw new AccountNotFoundException(); } return(account); }
public async Task <StockAction> GetByCorrelationIdAsync(string correlationId, CancellationToken cancellationToken) { StockAction?stockAction = await _appDbContext.Set <StockAction>() .FirstOrDefaultAsync(action => action.CorrelationId == correlationId, cancellationToken); if (stockAction == null) { throw new StockActionNotFoundException(correlationId); } return(stockAction); }
public async Task <StockSnapshot> GetByProductIdAsync(string productId, CancellationToken cancellationToken) { StockSnapshot?stockSnapshot = await _appDbContext.Set <StockSnapshot>() .FirstOrDefaultAsync(snapshot => snapshot.ProductId == productId, cancellationToken); if (stockSnapshot == null) { throw new StockSnapshotNotFoundException(productId); } return(stockSnapshot); }
public async Task <PaginatedCollection <Stock> > GetAsync(IExpressionSpecification <Stock> specification, int offset, int limit, OrderBy <Stock> orderBy, CancellationToken cancellationToken) { IQueryable <Stock> stocks = _appDbContext.Set <Stock>() .Where(specification.Expression); stocks = orderBy.Apply(stocks); (int totalCount, List <Stock> stockList) = await stocks.PaginatedQueryAsync(offset, limit, cancellationToken); if (!stockList.Any()) { throw new StockNotFoundException(); } var paginatedCollection = new PaginatedCollection <Stock>(totalCount, stockList); return(paginatedCollection); }
public async Task <PaginatedCollection <Order> > GetAsync(IExpressionSpecification <Order> specification, int offset, int limit, OrderBy <Order> orderBy, CancellationToken cancellationToken = default) { IQueryable <Order> books = _appDbContext.Set <Order>() .Include(order => order.OrderLines) .Where(specification.Expression); books = orderBy.Apply(books); (int totalCount, List <Order> orderList) = await books.PaginatedQueryAsync(offset, limit, cancellationToken); if (!orderList.Any()) { throw new OrderNotFoundException(); } var paginatedCollection = new PaginatedCollection <Order>(totalCount, orderList); return(paginatedCollection); }