public IActionResult Index(ManagerProductViewModel vm) { if (vm.EventCommand == "list") { vm.AllProductsCount = _ProductData.GetAll().Count(); vm.IsListAreaVisible = true; vm.IsSearchAreaVisible = true; vm.IsAddPhoneFormAreaVisible = false; vm.IsAddLaptopFormAreaVisible = false; vm.Products = _ProductData.GetPorductsofNum(vm.SkipDisplayList, vm.TakeDisplayList); } else if (vm.EventCommand == "search") { vm.IsListAreaVisible = true; vm.IsSearchAreaVisible = true; vm.IsAddPhoneFormAreaVisible = false; vm.IsAddLaptopFormAreaVisible = false; vm.Products = _ProductData.SearchByTitle(vm.ProductSearchName); vm.AllProductsCount = vm.Products.Count(); } else if (vm.EventCommand == "addPhone") { vm.IsListAreaVisible = false; vm.IsSearchAreaVisible = false; vm.IsAddPhoneFormAreaVisible = true; } else if (vm.EventCommand == "addLaptop") { vm.IsListAreaVisible = false; vm.IsSearchAreaVisible = false; vm.IsAddPhoneFormAreaVisible = false; vm.IsAddLaptopFormAreaVisible = true; vm.Products = _ProductData.GetAll(); } else if (vm.EventCommand.Contains("editPhone")) { string productID = vm.EventCommand.Replace("editPhone/", ""); vm.Phone = (Phone)_ProductData.FindProductById(int.Parse(productID)); vm.IsListAreaVisible = false; vm.IsSearchAreaVisible = false; vm.IsAddPhoneFormAreaVisible = false; vm.IsEditLaptopFormAreaVisible = false; vm.IsEditPhoneFormAreaVisible = true; } else if (vm.EventCommand.Contains("editLaptop")) { string productID = vm.EventCommand.Replace("editLaptop/", ""); vm.Laptop = (Laptop)_ProductData.FindProductById(int.Parse(productID)); vm.IsListAreaVisible = false; vm.IsSearchAreaVisible = false; vm.IsAddPhoneFormAreaVisible = false; vm.IsAddLaptopFormAreaVisible = false; vm.IsEditLaptopFormAreaVisible = true; } vm.SubDepartments = _DepartmentData.GetAllSubDepartments(); return(View(vm)); }
public IActionResult ChangeQty(CartPageViewModel vm) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var foundShoppingProduct = _shoppingCartData.FindCartProductById(vm.ShoppingCart.ProductId, userId); var foundProduct = _productData.FindProductById(vm.ShoppingCart.ProductId); var intendedChangeQty = vm.ShoppingCart.Qty; var originalQty = foundProduct.Quantity; if (intendedChangeQty <= originalQty) { decimal totalChangePrice = (intendedChangeQty - foundShoppingProduct.Qty) * foundProduct.Price; _shoppingCartData.ModifyQty(foundShoppingProduct, intendedChangeQty); return(Json(new { qty = intendedChangeQty, totalChangePrice = totalChangePrice, message = "success to change qty from " + originalQty + "to" + intendedChangeQty })); } else { return(Json(new { qty = originalQty, totalChangePrice = 0, message = "Sorry, We Don't have too much in stock" })); } }
public async Task <IActionResult> SaveForLater(int productId) { var vm = new CartModel(); var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (_shoppingCartData.CheckIsExistedInList(productId, userId)) { return(Json(new { success = false, responseText = "The attached file is not supported." })); } else { var foundShoppingProduct = _shoppingCartData.FindCartProductById(productId, userId); Product foundProduct = _productData.FindProductById(productId); _shoppingCartData.Delete(foundShoppingProduct); SaveForLater foundSaveForLater = _shoppingCartData.SaveForLater(productId, userId); vm = await InitModel(userId); return(Json(vm)); } }
public async Task <IActionResult> AddToCart(ClientProductPageViewModel vm) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; vm.EventCommand = "list"; if (!string.IsNullOrEmpty(userId)) { var currentUser = await _userManager.FindByIdAsync(userId); var foundProduct = _ProductData.FindProductById(vm.SaveToCartProductId); var foundShoppingProduct = _shoppingCartData.FindCartProductById(vm.SaveToCartProductId, userId); //if shopping cart dosen't have this product and product inventory is greater than 0 //simply save to cart if (foundShoppingProduct == null && foundProduct.Quantity > 0) { _ProductData.SaveToCart(vm.SaveToCartProductId, currentUser.Id); var foundqQty = _shoppingCartData.GetUserTotalSavedItems(userId); return(Json(new { success = true, message = "Add To Our Cart Now", qty = foundqQty })); } //if we don't have any instcok or custom already put all qty in her/his cart //we don't nothing else if (foundProduct.Quantity == 0 || foundProduct.Quantity == foundShoppingProduct.Qty) { vm.EventCommand = "list"; var foundqQty = _shoppingCartData.GetUserTotalSavedItems(userId); return(Json(new { success = false, message = "We don't have too much in stock for now", qty = foundqQty })); } else { _shoppingCartData.ModifyQty(foundShoppingProduct, foundShoppingProduct.Qty + 1); var foundqQty = _shoppingCartData.GetUserTotalSavedItems(userId); return(Json(new { success = true, message = "You already add this in your cart. I add one more qty for you", qty = foundqQty })); } } else { return(Json(new { success = false, message = "Please Login in first", qty = 0 })); } }