Skip to content

Instantly share code, notes, and snippets.

@pereiren
Created February 23, 2020 12:00
Show Gist options
  • Save pereiren/39f3e3417aea9912846ebfe56a1a2e81 to your computer and use it in GitHub Desktop.
Save pereiren/39f3e3417aea9912846ebfe56a1a2e81 to your computer and use it in GitHub Desktop.
public class CartService : ICartService
{
//...
CheckoutService checkoutDomainService;
public CartService(... CheckoutService checkoutDomainService ...)
{
//...
this.checkoutDomainService = checkoutDomainService;
}
public CheckOutResultDto CheckOut(Guid customerId)
{
CheckOutResultDto checkOutResultDto = new CheckOutResultDto();
Cart cart = this.cartRepository.FindOne(new CustomerCartSpec(customerId));
this.validateCart(customerId, cart);
Customer customer = this.customerRepository.FindById(cart.CustomerId);
Nullable<CheckOutIssue> checkOutIssue =
this.checkoutDomainService.CanCheckOut(customer, cart);
if (!checkOutIssue.HasValue)
{
Purchase purchase = this.checkoutDomainService.Checkout(customer, cart);
checkOutResultDto = Mapper.Map<Purchase, CheckOutResultDto>(purchase);
this.unitOfWork.Commit();
}
else
{
checkOutResultDto.CheckOutIssue = checkOutIssue;
}
return checkOutResultDto;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment