示例#1
0
        public void Handle(OrderApprovalRequest request)
        {
            var order = _orderRepository.GetById(request.OrderId);

            _orderRepository.Save(request.Approved
                                    ? order.Approve()
                                    : order.Reject());
        }
示例#2
0
        public void Handle(OrderApprovalRequest request)
        {
            var order = _orderRepository.GetById(request.OrderId);

            if (order.Status == OrderStatus.SHIPPED)
            {
                throw new OrderCannotBeShippedTwiceException();
            }

            if (request.Approved && order.Status == OrderStatus.REJECTED)
            {
                throw new RejectedOrderCannotBeApprovedException();
            }

            if (!request.Approved && order.Status == OrderStatus.APPROVED)
            {
                throw new ApprovedOrderCannotBeRejectedException();
            }

            order.Status = request.Approved ? OrderStatus.APPROVED : OrderStatus.REJECTED;
            _orderRepository.Save(order);
        }