Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("SaveForLaterID,BuyerID,Date,CreatedDate,LastUpdatedDate,IsActive")] SaveForLater saveForLater)
        {
            if (id != saveForLater.SaveForLaterID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(saveForLater);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SaveForLaterExists(saveForLater.SaveForLaterID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BuyerID"] = new SelectList(_context.Buyers, "BuyerID", "BuyerID", saveForLater.BuyerID);
            return(View(saveForLater));
        }
Пример #2
0
        public void DelteSaveToList(int ProductId, string userId)
        {
            SaveForLater DeleteProductList = this.GetSaveForLater(ProductId, userId);

            _context.Remove(DeleteProductList);
            _context.SaveChanges();
        }
Пример #3
0
        public SaveForLater SaveForLater(int ProductId, string userId)
        {
            SaveForLater newProduct = new SaveForLater();

            newProduct.ProductId = ProductId;
            newProduct.UserId    = userId;
            _context.Add(newProduct);
            _context.SaveChanges();
            return(newProduct);
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("SaveForLaterID,BuyerID,Date,CreatedDate,LastUpdatedDate,IsActive")] SaveForLater saveForLater)
        {
            if (ModelState.IsValid)
            {
                _context.Add(saveForLater);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BuyerID"] = new SelectList(_context.Buyers, "BuyerID", "BuyerID", saveForLater.BuyerID);
            return(View(saveForLater));
        }
        public IActionResult SaveForLater(CartPageViewModel vm)
        {
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (_shoppingCartData.CheckIsExistedInList(vm.SaveForLater.ProductId, userId))
            {
                return(Json(new { success = false, responseText = "The attached file is not supported." }));
            }
            else
            {
                var foundShoppingProduct = _shoppingCartData.FindCartProductById(vm.SaveForLater.ProductId, userId);

                Product foundProduct     = _productData.FindProductById(vm.SaveForLater.ProductId);
                decimal totalChangePrice = (-foundShoppingProduct.Qty) * vm.ProductPrice;
                _shoppingCartData.Delete(foundShoppingProduct);
                SaveForLater foundSaveForLater = _shoppingCartData.SaveForLater(vm.SaveForLater.ProductId, userId);
                return(Json(new { success = true, list = foundSaveForLater, totalChangePrice = totalChangePrice }));
            }
        }
Пример #6
0
        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));
            }
        }