public async Task <IActionResult> CustomizeProduct(SelectCustomizeProductViewModel selectCustomizeProductViewModel) { if (selectCustomizeProductViewModel.Ingredients.Any() && selectCustomizeProductViewModel.ProductItemId > 0) { double subTotal = 0; var productItem = await _productItemService.GetProductItemAsync(selectCustomizeProductViewModel.ProductItemId); foreach (var item in selectCustomizeProductViewModel.Ingredients) { var ingredient = await _ingredientService.GetIngredientAsync(item.IngredientId); subTotal += ingredient.Price * item.Quantity; } var total = productItem.Price + subTotal; var customizeProduct = new CustomizeProduct() { Name = "Customize " + productItem.Name, ProductItemId = selectCustomizeProductViewModel.ProductItemId, Price = total }; var customProduct = await _customizeProductService.AddCustomizeProductAsync(customizeProduct); foreach (var item in selectCustomizeProductViewModel.Ingredients) { var customizeProductIngredient = new CustomizeProductIngredients() { CustomizeProductId = selectCustomizeProductViewModel.ProductItemId, IngredientId = item.IngredientId }; await _customizeProductIngredientService.AddCustomizeProductIngredientAsync(customizeProductIngredient); } await _shoppingCartService.AddToCartAsync(null, null, customProduct, 1, Session.ShoppingCartId); return(Json(1)); } return(Json(0)); }
public async Task AddToCartAsync(ProductItem productItem, ComboMeal comboMeal, CustomizeProduct customizeProduct, int quantity, string shoppingCartId) { await _shoppingCartRepository.AddToCartAsync(productItem, comboMeal, customizeProduct, quantity, shoppingCartId); }
public async Task AddToCartAsync(ProductItem productItem, ComboMeal comboMeal, CustomizeProduct customizeProduct, int quantity, string shoppingCartId) { try { if (productItem != null) { var shoppingCartItem = await _context.ShoppingCartItems.SingleOrDefaultAsync( s => s.ShoppingCartId == shoppingCartId && s.ProductItemId == productItem.Id); if (shoppingCartItem == null) { shoppingCartItem = new ShoppingCartItem { ShoppingCartId = shoppingCartId, ProductItem = productItem, ComboMeal = null, CustomizeProduct = null, Quantity = quantity }; await _context.ShoppingCartItems.AddAsync(shoppingCartItem); } else { shoppingCartItem.Quantity = quantity; } } if (comboMeal != null) { var shoppingCartItem = await _context.ShoppingCartItems.SingleOrDefaultAsync( s => s.ShoppingCartId == shoppingCartId && s.ComboMealId == comboMeal.Id); if (shoppingCartItem == null) { shoppingCartItem = new ShoppingCartItem { ShoppingCartId = shoppingCartId, ProductItem = null, ComboMeal = comboMeal, CustomizeProduct = null, Quantity = quantity }; await _context.ShoppingCartItems.AddAsync(shoppingCartItem); } else { shoppingCartItem.Quantity = quantity; } } if (customizeProduct != null) { var shoppingCartItem = new ShoppingCartItem { ShoppingCartId = shoppingCartId, ProductItem = null, ComboMeal = null, CustomizeProduct = customizeProduct, Quantity = quantity }; await _context.ShoppingCartItems.AddAsync(shoppingCartItem); } await _context.SaveChangesAsync(); } catch (Exception ex) { throw ex; } }
public async Task <CustomizeProduct> AddCustomizeProductAsync(CustomizeProduct customizeProduct) { return(await _customizeProductRepository.AddAsync(customizeProduct)); }