//
        // GET: /Store/AddToCart/5
        public ActionResult AddToCart(int id)
        {
            // Retrieve the album from the database
            // car redirect oto cation  vo in side of yoru lll uuu ;
            var addedAlbum = storeDB.ProductSpc
                .Single(album => album.ProductSpcId == id);

            // Add it to the shopping cart
            var cart = ShoppingCart.GetCart(this.HttpContext);
            cart.AddToCart(addedAlbum);
            int itemCount = cart.UpdateShoping1(id);



            if (Request.IsAjaxRequest())
            {
                var data = new ShoppingCartRemoveViewModel
                {
                    ItemCount = itemCount,
                    CartTotal = cart.GetCount(),
                    //Message=""+cart.GetCount(),
                    CartTotalPoint=cart.GetTotalPoint(),

                    Message = "" + cart.GetCount(),
                    Message2 = "This item has been added to your cart"
                };
                return Json(data, JsonRequestBehavior.AllowGet);
            }




            // Go back to the main store page for more shopping
            return RedirectToAction("Index");
        }
        public ActionResult remoALL(int id)
        {

            var cart = ShoppingCart.GetCart(this.HttpContext);

            string albumName = storeDB.Carts
                .Single(item => item.RecordId == id).ProductSpc.Title;
            int itemCount = 0;
            for (int i = 0; i < 10; i++)
            {
                itemCount = cart.RemoveFromCart(id);
            }
            var results = new ShoppingCartRemoveViewModel
            {
                Message = Server.HtmlEncode(albumName) +
                    " has been removed from your shopping cart.",
                CartTotal = cart.GetTotal(),
                CartTotalPoint = cart.GetTotalPoint(),
                CartCount = cart.GetCount(),
                ItemCount = itemCount,
                DeleteId = id
            };
            return Json(results);
        }
        public ActionResult RemoveFromCart(int id)
        {
            // Remove the item from the cart
            var cart = ShoppingCart.GetCart(this.HttpContext);

            // Get the name of the album to display confirmation
            string albumName = storeDB.Carts
                .Single(item => item.RecordId == id).ProductSpc.Title;

            // Remove from cart
            int itemCount = cart.RemoveFromCart(id);

            // Display the confirmation message
            var results = new ShoppingCartRemoveViewModel
            {
                Message = Server.HtmlEncode(albumName) +
                    " has been removed from your shopping cart.",
                CartTotal = cart.GetTotal(),
                CartTotalPoint = cart.GetTotalPoint(),
                CartCount = cart.GetCount(),
                ItemCount = itemCount,
                DeleteId = id
            };
            return Json(results);
        }
        //


        public ActionResult UpdateShoping2(int id)
        {
            var cart = ShoppingCart.GetCart(this.HttpContext);

            int itemCount = cart.UpdateShoping2(id);
            var s = cart.GetTotal();
            var results = new ShoppingCartRemoveViewModel
            {

                CartTotal = cart.GetTotal(),
                CartTotalPoint = cart.GetTotalPoint(),
                CartCount = cart.GetCount(),
                ItemCount = itemCount,


            };
            return Json(results);



        }
        public ActionResult Add(int Id)
        {

            try { 
            string userName = User.Identity.GetUserName();

            var exists = db.WishLists.Where(p => p.ProductSpcId == Id);
            int i = 0;
            foreach (WishList we in exists)
            {
                if (we.userName == userName)
                {
                    i++;
                }
            }



            if (i == 0)
            {

                var wishlist = new WishList();

                wishlist.ProductSpcId = Id;
                wishlist.DateCreated = System.DateTime.Now;
                ProductSPc product = db.ProductSpc.Find(Id);
                wishlist.ProductSpc = product;
                wishlist.userName = User.Identity.GetUserName();
                db.WishLists.Add(wishlist);
                db.SaveChanges();
                var results = new ShoppingCartRemoveViewModel
                {
                    Message = "" + product.Title + "  has been added to Your WishList "


                };

                return Json(results, JsonRequestBehavior.AllowGet);





            }
            else
            {
                var results = new ShoppingCartRemoveViewModel
                {
                    Message = "This item is allready in your Wishlist"


                };

                return Json(results, JsonRequestBehavior.AllowGet);


            }
                }
            catch { 
            var error = new ShoppingCartRemoveViewModel
            {
                Message = "Some Error Happend"


            };

            return Json(error, JsonRequestBehavior.AllowGet);
            }


        }
        public ActionResult remove(int id)
        {
            WishList wishlist = db.WishLists.Find(id);
            string name = wishlist.ProductSpc.Title;
            string username = User.Identity.GetUserName();
            db.WishLists.Remove(wishlist);
            db.SaveChanges();
            var isempty = db.WishLists.Where(w => w.userName.ToString() == username).ToList();

            if (isempty.Count > 0)
            {
                ViewData["Tarek"] = 1;

                var result = new ShoppingCartRemoveViewModel
                {
                    CartTotal = 5,
                    Message = name + " has been removed from wishlist"
                };
                return Json(result, JsonRequestBehavior.AllowGet);

            }
            else
            {
                ViewData["Tarek"] = 0;
                var result = new ShoppingCartRemoveViewModel
                {
                    CartTotal = 0,
                    Message = name + " has been removed from wishlist"
                };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

           
        }