示例#1
0
        public async Task <Unit> Handle(OrderUpdateCommand request, CancellationToken cancellationToken)
        {
            var customerEmail = _userContextManager.GetCurrentUserEmail();
            var order         = await _context.Orders.FirstOrDefaultAsync(x => x.Id == request.OrderId && x.CustomerEmail == customerEmail, cancellationToken);

            order.SetStatus(request.Status);
            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
        public async Task <Guid> Handle(OrderCreateCommand request, CancellationToken cancellationToken)
        {
            var customerEmail = _userContextManager.GetCurrentUserEmail();
            var order         = new Order(customerEmail);

            _context.Orders.Add(order);
            await _context.SaveChangesAsync(cancellationToken);

            return(order.Id);
        }
        public async Task <Unit> Handle(OrderProductCreateCommand request, CancellationToken cancellationToken)
        {
            var customerEmail = _userContextManager.GetCurrentUserEmail();
            var order         = await _context.Orders.Include(x => x.OrderProducts).FirstOrDefaultAsync(x => x.Id == request.OrderId && x.CustomerEmail == customerEmail, cancellationToken);

            order.AddProduct(request.ProductId, request.Quantity);
            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }