コード例 #1
0
        public void Run(OrderApprovalRequest request)
        {
            var order = orderRepository.GetById(request.OrderId);

            if (request.Approved)
            {
                order.Approve();
            }
            else
            {
                order.Reject();
            }
            orderRepository.Save(order);
        }
コード例 #2
0
        public void Run(OrderApprovalRequest request)
        {
            var order = orderRepository.GetById(request.OrderId);

            if (order.Status == OrderStatus.Shipped)
            {
                throw new ShippedOrdersCannotBeChangedException();
            }

            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);
        }
コード例 #3
0
        public void Run(OrderApprovalRequest request)
        {
            Order order = orderRepository.GetById(request.GetOrderId());

            if (order.GetStatus().Equals(OrderStatus.Shipped))
            {
                throw new ShippedOrdersCannotBeChangedException();
            }

            if (request.IsApproved() && order.GetStatus().Equals(OrderStatus.Rejected))
            {
                throw new RejectedOrderCannotBeApprovedException();
            }

            if (!request.IsApproved() && order.GetStatus().Equals(OrderStatus.Approved))
            {
                throw new ApprovedOrderCannotBeRejectedException();
            }

            order.SetStatus(request.IsApproved() ? OrderStatus.Approved : OrderStatus.Rejected);
            orderRepository.Save(order);
        }