public override Task PreRender()
        {
            using (var db = new Database())
            {
                CartItem = Convert.ToInt32(CartService.GetCartCountItem());
                ProductService.LoadProduct(Products);
                if (CartItem < 0)
                {
                    CartItem = 0;
                }
            }

            return(base.PreRender());
        }
        public void AddToCart(int productid)
        {
            if (UserService.GetCurrentUserId() != null)
            {
                using (var db = new Database())
                {
                    var user    = db.Users.Find(UserService.GetCurrentUserId());
                    var id      = user.UserID;
                    var product = db.Products.Find(productid);
                    var citem   = new CartItem();
                    var query   = from p in db.Carts
                                  where p.UserID == id
                                  select p;
                    citem.Price     = product.Price;
                    citem.Name      = product.Name;
                    citem.ProductID = product.ProductID;
                    citem.image     = product.Image;

                    var cart = query.FirstOrDefault();

                    if (query.Count() != 0)
                    {
                        cart.Count++;
                        citem.CartID = cart.CartID;
                        user.CartID  = cart.CartID;
                        cart.CartItems.Add(citem);
                        db.SaveChanges();
                        CartItem = Convert.ToInt32(CartService.GetCartCountItem());
                    }
                    else
                    {
                        var newcart = new Cart();
                        newcart.Count  = 1;
                        newcart.UserID = id;
                        user.CartID    = newcart.CartID;
                        citem.CartID   = newcart.CartID;
                        newcart.CartItems.Add(citem);
                        db.Carts.Add(newcart);
                        db.SaveChanges();
                        CartItem = Convert.ToInt32(CartService.GetCartCountItem());
                    }
                }
            }
            else
            {
                GoLogin = true;
            }
        }