public async Task <Order> GetOrderWithWithStocksAndProductsById(int id) { var entityOrder = await _ctx.Orders .Where(x => x.Id == id) .Include(x => x.OrderStocks) .ThenInclude(x => x.Stock) .ThenInclude(x => x.Product) .SingleOrDefaultAsync(); if (entityOrder is null) { throw new ArgumentException("There is no such order."); } var order = Projections.EntityOrderToDomainOrder(entityOrder); order.OrderStocks = entityOrder.OrderStocks.Select(x => { var orderStock = new OrderStock { StockId = x.StockId, Qty = x.Qty, Stock = Projections.EntityStockToDomainStock(x.Stock), }; orderStock.Stock.Product = Projections.EntityProductToDomainProduct(x.Stock.Product); return(orderStock); }); return(order); }
public async Task <IEnumerable <Order> > GetOrdersByStatus(OrderStatus status) { return(await _ctx.Orders .Where(x => x.Status == status) .Select(x => Projections.EntityOrderToDomainOrder(x)) .ToListAsync()); }
public async Task <Order> GetOrderByReference(string reference) { var order = await _ctx.Orders.SingleOrDefaultAsync(x => x.OrderRef == reference); if (order is null) { throw new ArgumentException("There is no such order."); } return(Projections.EntityOrderToDomainOrder(order)); }
//private TResult GetOrder<TResult>( // Expression<Func<Order, bool>> condition, // Func<Order, TResult> selector) //{ // return _ctx.Orders // .Where(condition) // .Include(x => x.OrderStocks) // .ThenInclude(x => x.Stock) // .ThenInclude(x => x.Product) // .Select(selector) // .FirstOrDefault(); //} public async Task <Order> GetOrderById(int id) { var order = await _ctx.Orders.FindAsync(id); if (order is null) { throw new ArgumentException("There is no such order."); } return(Projections.EntityOrderToDomainOrder(order)); }