public CartDto Add(Guid customerId, CartProductDto productDto) { CartDto cartDto = null; Customer customer = this.customerRepository.FindById(customerId); if (customer == null) { throw new Exception(String.Format("Customer was not found with this Id: {0}", customerId)); } Cart cart = this.cartRepository.FindOne(new CustomerCartSpec(customerId)); if (cart == null) { cart = Cart.Create(customer); this.cartRepository.Add(cart); } Product product = this.productRepository.FindById(productDto.ProductId); this.validateProduct(product.Id, product); //Double Dispatch Pattern cart.Add(CartProduct.Create(customer, cart, product, productDto.Quantity, taxDomainService)); cartDto = Mapper.Map <Cart, CartDto>(cart); this.unitOfWork.Commit(); return(cartDto); }
public CartDto Add(Guid customerId, CartProductDto productDto) { CartDto cartDto = null; var customre = _customerRepository.FindById(customerId); if (customre == null) { throw new Exception(String.Format("Customer was not found with this Id: {0}", customerId)); } var cart = _cartRepository.FindOne(new CustomerCartSpec(customerId)); if (cart == null) { cart = Cart.Create(customre); _cartRepository.Add(cart); } var product = _productRepository.FindById(productDto.ProductId); validateProduct(product.Id, product); cart.Add(CartProduct.Create(customre, cart, product, productDto.Quantity, _taxService)); cartDto = _mapper.Map <Cart, CartDto>(cart); _unitOfWork.Commit(); return(cartDto); }
/// <summary> /// Adds the specified model. /// </summary> /// <param name="model">The model.</param> public void Add(AddProudctToCartViewModel model) { var customer = _customerRepository.FindById(model.CustomerId); if (customer == null) { _eventDispatcher.RaiseEvent(new DomainNotification(MessageType, string.Format("Customer was not found with this Id: {0}", model.CustomerId))); return; } var product = _productRepository.FindById(model.ProductId); if (product == null) { _eventDispatcher.RaiseEvent(new DomainNotification(MessageType, string.Format("Product was not found with this Id: {0}", model.ProductId))); return; } var cart = _cartRepository.FindSingleBySpec(new CustomerCartSpec(model.CustomerId)); if (cart == null) { cart = Cart.Create(customer); _cartRepository.Add(cart); } cart.Add(CartProduct.Create(customer, cart, product, model.Quantity)); }
public CartDto Add(Guid customerId, CartProductDto productDto) { CartDto cartDto = null; Customer customer = this.repositoryCustomer.FindById(customerId); this.validateCustomer(customerId, customer); Product product = this.repositoryProduct.FindById(productDto.ProductId); this.validateProduct(product.Id, product); //Double Dispatch Pattern customer.Cart.Add(CartProduct.Create(customer.Cart, product, productDto.Quantity, taxDomainService)); cartDto = Mapper.Map <Cart, CartDto>(customer.Cart); this.unitOfWork.Commit(); return(cartDto); }
public CartDTO Add(Guid customerId, CartProductDTO cartProductDto) { CartDTO cartDto = null; Cart cart = null; CustomerDTO customerDto = this.customerRepository.FindOne(c => c.Id == customerId); if (customerDto == null) { throw new Exception(String.Format("Customer was not found with this Id: {0}", customerId)); } Customer customer = Customer.Create( new PlainText(customerDto.FirstName), new PlainText(customerDto.LastName), new Email(customerDto.Email), Country.Create(new PlainText("Romania")) ); cartDto = this.cartRepository.FindOne(c => c.CustomerId == customerId); if (cartDto == null) { cart = Cart.Create(customer); } else { cart = new Cart() { CustomerId = customerId, Id = cartDto.Id }; //foreach(var cardP in cartDto.Products) //{ // cart.Add(cardP); //} } ProductDTO productDto = this.productRepository.FindOne(c => c.Id == cartProductDto.ProductId); Product product = Product.Create( new PlainText(productDto.Name), new Quantity(productDto.Quantity), new Cost(productDto.Cost), ProductCode.Create(new PlainText("test")), new PlainText(productDto.Description), productDto.Image ); var cartP = CartProduct.Create(customer, cart, product, new Quantity(1)); cart.Add(new CartProductDTO() { Id = cartP.Id, CartDTOId = cart.Id, ProductId = cartP.ProductId }); Console.WriteLine(JsonConvert.SerializeObject(cart)); // cartDto = _mapper.Map<Cart, CartDTO>(cart); cartDto = new CartDTO() { Created = DateTime.Today, CustomerId = customerId, Modified = DateTime.Today, Id = cart.Id, Products = cart.Products.ToList() }; this.cartRepository.Create(cartDto); this.cartRepository.Save(); return(cartDto); }