public async Task <OrderDto> Handle(GetOrderByIdQuery request, CancellationToken cancellationToken)
        {
            var order = await _context.Orders
                        .Include(o => o.OrderItems)
                        .SingleAsync(o => o.Id == request.OrderId);

            var permissions = _permissionsManager.GetCurrentUserPermissions();

            return(new OrderDto(order)
            {
                SubTotal = _ordersDomainService.CalculateSubTotal(order),
                Tax = _ordersDomainService.CalculateTax(order),
                Discount = _ordersDomainService.CalculateDiscount(order),
                Total = _ordersDomainService.CalculateTotalPrice(order)
            });
        }
Exemple #2
0
        public async Task <List <OrderDto> > Handle(GetAllOrdersQuery request, CancellationToken cancellationToken)
        {
            var orders = await _context.Orders
                         .Include(o => o.OrderItems)
                         .ToListAsync();

            return(orders
                   .Select(order => new OrderDto(order)
            {
                SubTotal = _ordersDomainService.CalculateSubTotal(order),
                Tax = _ordersDomainService.CalculateTax(order),
                Discount = _ordersDomainService.CalculateDiscount(order),
                Total = _ordersDomainService.CalculateTotalPrice(order)
            })
                   .ToList());
        }