Ejemplo n.º 1
0
        public ActionResult AddCart(int id)
        {
            try
            {
                if (Session["CustomerId"] != null)
                {
                    int CustomerId = Convert.ToInt32(Session["CustomerId"]);
                    int CartId     = balCustomer.CartCustomerExist(CustomerId);
                    if (CartId == 0)
                    {
                        bool addCart = balCustomer.AddCart(CustomerId);
                        CartId = balCustomer.CartCustomerExist(CustomerId);
                    }
                    bool ProductIdExist = balCustomer.CartProductExist(CartId, id);

                    if (ProductIdExist)
                    {
                        if (!balCustomer.AddQuantity(CartId, id))
                        {
                            TempData["Error"] = "Product out of stock...";
                        }
                    }
                    else
                    {
                        if (!balCustomer.AddCartItem(CartId, id))
                        {
                            TempData["Error"] = "Product out of stock...";
                        }
                    }
                }
                else
                {
                    TempData["Error"] = "Please SignIn first...";
                }
                //Session["CartCount"] = CartCount();
                return(Redirect("/Clothes/Clothes"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }