public void Handle(OrderApprovalRequest request) { var order = _orderRepository.GetById(request.OrderId); _orderRepository.Save(request.Approved ? order.Approve() : order.Reject()); }
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); }