public ActionResult Index()
        {
            UpdateProductState update = new UpdateProductState();

            update.ChangeProductStateAddedToCart();
            FindAllProductsByState rep = new FindAllProductsByState();
            var products = rep.GetAvailableProducts();

            foreach (var p in products)
            {
                if (Request.Cookies["userName"] != null && Request.Cookies["userName"].Value != null)
                {
                    p.price = p.price * Convert.ToDecimal(0.9);
                }
            }
            return(View(products));
        }
Exemple #2
0
        public ActionResult AddToCart(long ID)
        {
            FindAllProductsByState product = new FindAllProductsByState();
            UpdateProductState     update  = new UpdateProductState();

            foreach (var p in product.GetAvailableProducts())
            {
                if (p.ID == ID)
                {
                    if (Request.Cookies["userName"] != null && Request.Cookies["userName"].Value != null)
                    {
                        FindUserRepository find = new FindUserRepository();
                        p.userID = find.FindUserId(Request.Cookies["userName"].Value);
                        update.ChangeProductStateToCart(ID, p.userID);
                        SetTimer(p);
                    }
                    else
                    {
                        if (Session["cart"] == null)
                        {
                            List <ProductsModel> list = new List <ProductsModel>();
                            list.Add(p);
                            Session["cart"] = list;
                        }
                        else
                        {
                            List <ProductsModel> list = (List <ProductsModel>)Session["cart"];
                            list.Add(p);
                            Session["cart"] = list;
                        }
                        update.ChangeStateToCartGuest(p.ID);
                    }
                }
            }
            return(RedirectToAction("Index", "Home"));
        }