/// <summary> /// /// </summary> /// <param name="shoppingProductModel"></param> /// <returns></returns> public ShoppingProduct CreateShoppingProduct(ShoppingProductModel shoppingProductModel) { var newShoppingProduct = new ShoppingProduct { Name = shoppingProductModel.name, Price = shoppingProductModel.pricePerUnit, Product = _productRepository.GetById(shoppingProductModel.productId), Quantity = shoppingProductModel.quantity }; _shoppingProductRepository.Add(newShoppingProduct); _context.SaveChanges(); return(newShoppingProduct); }
/// <summary> /// /// </summary> /// <param name="cart"></param> /// <param name="productId"></param> /// <param name="quantity"></param> /// <param name="returnUrl"></param> /// <returns></returns> //[HttpPost] public async Task <ActionResult> AddToCart(ShoppingCartModel cart, int productId, int quantity) { var productModel = await productService.GetProduct(productId); ShoppingProductModel shoppingProductModel = new ShoppingProductModel() { name = productModel.name, pricePerUnit = productModel.price, productId = productModel.id, quantity = quantity }; cart.shoppingProducts.Add(shoppingProductModel); return(RedirectToAction("Index")); }
public static ShoppingProductModel Create(ShoppingProduct product) { if (product == null) { return(null); } var productModel = new ShoppingProductModel { id = product.Id, name = product.Name, pricePerUnit = product.Price, productId = product.Product == null ? 0 : product.Product.Id, quantity = product.Quantity }; return(productModel); }