public JsonResult AddToCart(Cart cart)
        {
            var exceptionMessage = string.Empty;

            try
            {
                string cartId = string.Empty;
                cartId = this.cartRepo.GetCartId(this.HttpContext);

                if (User.Identity.IsAuthenticated)
                {
                    cartId = User.Identity.Name;
                }
                cartId           = this.cartRepo.GetCartId(this.HttpContext);
                cart.Count       = 1;
                cart.DateCreated = DateTime.Now;
                cart.CartId      = cartId;

                if (cartRepo.AddToCart(cart))
                {
                    return(Json(new { error = false }, JsonRequestBehavior.AllowGet));
                }

                return(Json(new { error = true, message = "Error adding item to cart" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                exceptionMessage = ex.Message;
            }

            return(Json(new { error = true, message = exceptionMessage }, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public async Task <IActionResult> AddToCart(string username, int productId, int quantity)
        {
            if (ModelState.IsValid)
            {
                var cart = await _cart.GetCart(username);

                var product = await _inventory.GetProduct(productId);

                var updateCI = await _cart.GetCartItem(cart.ID, product.ID);

                if (updateCI != null)
                {
                    updateCI.Quantity += quantity;
                    await _cart.UpdateQuantity(updateCI);
                }
                else
                {
                    CartItem newCartItem = new CartItem()
                    {
                        CartID    = cart.ID,
                        ProductID = product.ID,
                        Quantity  = quantity
                    };

                    await _cart.AddToCart(newCartItem);
                }
            }
            return(RedirectToAction("Index", "Cart", new { username = username }));
        }
示例#3
0
 public IActionResult AddToUserCart(AddToCartModel addToCartModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             UserCartDetails cartModel = CartHelper.BindUserCartDetails(addToCartModel);
             cartModel.CreatedOn = DateTime.Now;
             long cartId = iCart.AddToCart(cartModel);
             if (cartId > 0)
             {
                 //return Ok(ResponseHelper.Success(MessageConstants.AddedToCart));
                 return(Ok(ResponseHelper.Success(cartId)));
             }
             else if (cartId == ReturnCode.AlreadyExist.GetHashCode())
             {
                 return(Ok(ResponseHelper.Error(MessageConstants.ExistInCart)));
             }
             else
             {
                 return(Ok(ResponseHelper.Error(MessageConstants.NotAddedToCart)));
             }
         }
         else
         {
             return(Ok(ResponseHelper.Error(MessageConstants.CompulsoryData)));
         }
     }
     catch (Exception ex)
     {
         LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
         return(Ok(ResponseHelper.Error(ex.Message)));
     }
 }
示例#4
0
        public IActionResult AddToCart(int productid, int q = 1)
        {
            var userid = Int32.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier));

            _cart.AddToCart(productid, userid, q);
            return(View("ItemAdded"));
        }
示例#5
0
        public async Task <JsonResult> Create(Guid id)
        {
            string userId = User.Identity.GetUserId();
            await _cart.AddToCart(id, userId);

            return(Json("Proccess completed successfuly", JsonRequestBehavior.AllowGet));
        }
示例#6
0
        //
        // GET: /Store/AddToCart/5
        public ActionResult AddToCart(int id)
        {
            //_cartService.StartCart(HttpContext);
            _cartService.AddToCart(id);

            // Go back to the main store page for more shopping
            return(RedirectToAction("Cart"));
        }
        public void Shopping()
        {
            List <string> products  = _marketplace.Products();
            List <int>    choosings = _hand.Picking(products);
            List <string> cart      = _cart.AddToCart(products, choosings);

            Console.SetCursorPosition(0, Console.CursorTop + 1);
            Console.WriteLine("Your bag consists of: ");
            foreach (string item in cart)
            {
                Console.WriteLine(item);
            }
        }
示例#8
0
        public async Task <IActionResult> OnPost(CategoryItemViewModel productDetails)
        {
            if (productDetails?.Id == null)
            {
                return(View("Index", CartModel));
            }
            await SetCartModelAsync();

            await _cartService.AddToCart(CartModel.Id, productDetails.Id, productDetails.Price, 1);

            await SetCartModelAsync();

            return(View("Index", CartModel));
        }
示例#9
0
        public async Task <bool> Handle(AddToCartCommand request, CancellationToken cancellationToken)
        {
            var game = _gameService.GetByID(request.GameID);

            try
            {
                var user = await _userManager.FindByIdAsync(request.UserID);

                _cartService.AddToCart(user.CartID, game);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#10
0
        public IActionResult AddToCart(string returnUrl, [Bind("ProductName")] Cart cartItem)
        {
            if (HttpContext.Session.GetString("Cart") == null)
            {
                _cart.RemoveCart();
            }
            var item = new Cart()
            {
                ProductName = cartItem.ProductName,
                RoomId      = cartItem.RoomId,
            };
            int result = _cart.AddToCart(item);

            if (result == 0)
            {
                HttpContext.Session.SetString("Cart", JsonConvert.SerializeObject(_cart.GetCart()));
            }
            else
            {
                TempData["AddError"] = "Product existed !!!";
            }
            return(Redirect(returnUrl));
        }
示例#11
0
 public void AddToCart(int productId)
 {
     _cart.AddToCart(productId);
     _cart.VerifyStock(productId);
     _cart.LockItem(productId);
 }
        public async Task <ActionResult <Cart> > PostCart(Cart cart)
        {
            var result = await _cartService.AddToCart(cart);

            return(Ok(new { status = result }));
        }
 private void AddToCart(int beverageId, int amount)
 {
     _cart.AddToCart(beverageId, amount);
     _cartControl.PrintOrders();
 }
示例#14
0
 // GET: Cart
 public ActionResult AddToCart(string mod)
 {
     cart.AddToCart(mod, Session["email"] + "");
     return(RedirectToAction("ViewCart"));
 }
示例#15
0
        public IActionResult Index(int Id)
        {
            var allProducts   = _product.GetProducts();
            var singleProduct = _product.GetProductById(Id);

            var model = new IndexViewModel();

            if (singleProduct != null)
            {
                // add new product to cart
                var productToCart = new Cart
                {
                    ProdId    = singleProduct.ProdId,
                    ProdName  = singleProduct.ProductName,
                    UnitPrice = singleProduct.Price,
                    AddedBy   = 1,
                };

                //**********reduce the card item quantity*************//
                if ((singleProduct.Quantity - 1) >= 0)
                {
                    singleProduct.Quantity -= 1;
                    _product.UpdateProduct(singleProduct);

                    _cart.AddToCart(productToCart);
                }
                //******************************************************//


                // get items added by current user
                var result = _cart.GetItemsAddedByUser(1);

                // group items by product and get the quantity and total price
                var quantity = from r in result group r by r.ProdId into newGroup
                               select new { Id    = newGroup.Key, qty = newGroup.Count(),
                                            total = newGroup.Sum(x => x.UnitPrice), };

                var list = new List <CartProductsViewModel>();
                // construct each object with total quantity and total price
                foreach (var item in quantity)
                {
                    var cartModel = new CartProductsViewModel
                    {
                        Id          = model.CartProducts.Count() + 1,
                        ProductId   = item.Id,
                        ProductName = _product.GetProductById(item.Id).ProductName,
                        Quantity    = item.qty,
                        UnitPrice   = _product.GetProductById(item.Id).Price,
                        Price       = item.total
                    };
                    list.Add(cartModel);
                }

                // add to view model
                model.CardProducts = allProducts;
                model.CartProducts = list;
                model.GrandTotal   = quantity.Sum(x => x.total);
                return(View(model));
            }

            model.CardProducts = allProducts;
            model.CartProducts = null;
            model.GrandTotal   = 0;
            return(View(model));
        }
示例#16
0
 public void Post([FromBody] MenuItem value)
 {
     var i = _cartRepo.AddToCart(value);
 }
示例#17
0
 public IHttpActionResult AddtoCart(Cart request)
 {
     return(Ok(_cart.AddToCart(request)));
 }
 public IActionResult AddToCart(int productid, int userid = 6, int q = 1)
 {
     _cart.AddToCart(productid, userid, q);
     return(View("ItemAdded"));
 }