public void Run(OrderApprovalRequest request) { var order = orderRepository.GetById(request.OrderId); if (request.Approved) { order.Approve(); } else { order.Reject(); } orderRepository.Save(order); }
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); }
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); }