public CheckOutResultDto CheckOut(Guid customerId) { var checkOutResultDto = new CheckOutResultDto(); var cart = _cartRepository.FindOne(new CustomerCartSpec(customerId)); validateCart(customerId, cart); var customer = _customerRepository.FindById(customerId); var checkOutIssue = _checkoutDomainService.CanCheckOut(customer, cart); if (!checkOutIssue.HasValue) { var purchase = _checkoutDomainService.Checkout(customer, cart); checkOutResultDto = _mapper.Map <Purchase, CheckOutResultDto>(purchase); _unitOfWork.Commit(); } else { checkOutResultDto.CheckOutIssue = checkOutIssue; } return(checkOutResultDto); }
/// <summary> /// Checks the out. /// </summary> /// <param name="customerId">The customer identifier.</param> /// <returns>CheckOutResultDto.</returns> /// <exception cref="System.NotImplementedException"></exception> public CheckOutResultDto CheckOut(Guid customerId) { var checkOutResultDto = new CheckOutResultDto(); var cart = _cartRepository.FindSingleBySpec(new CustomerCartSpec(customerId)); if (cart == null) { _eventDispatcher.RaiseEvent(new DomainNotification(GetType().Name, string.Format("Cart was not found with this customer Id: {0}", customerId))); return(null); } if (!cart.Products.Any()) { _eventDispatcher.RaiseEvent(new DomainNotification(GetType().Name, "Cart was not found any items")); return(null); } var customer = _customerRepository.FindById(cart.CustomerId); if (customer == null) { _eventDispatcher.RaiseEvent(new DomainNotification(GetType().Name, string.Format("Customer was not found with this Id: {0}", cart.CustomerId))); return(null); } var checkOutIssue = _checkoutDomainService.CanCheckOut(customer, cart); if (checkOutIssue == null) { var purchase = _checkoutDomainService.Checkout(customer, cart); checkOutResultDto = _mapper.Map <Purchase, CheckOutResultDto>(purchase); _unitOfWork.Commit(); } else { checkOutResultDto.CheckOutIssue = checkOutIssue; } return(checkOutResultDto); }