Exemplo n.º 1
0
    private void AddToCart(DataListCommandEventArgs e, ShoppingCartItem cart)
    {
        LoadProducts(categoryId);

        cart.ProductId   = ProductDataList.DataKeys[e.Item.ItemIndex].ToString();
        cart.ProductName = (e.Item.FindControl("ProductDetailLink") as HyperLink).Text;
        cart.UnitPrice   = decimal.Parse((e.Item.FindControl("UnitPriceLabel") as Label).Text);
        TextBox quantityTextBox = (e.Item.FindControl("QuantityTextBox") as TextBox);

        if (quantityTextBox.Text.Equals(string.Empty))
        {
            cart.Quantity = 1;
        }
        else
        {
            cart.Quantity = int.Parse(quantityTextBox.Text);
        }
        cart.Total = cart.UnitPrice * cart.Quantity;

        ShoppingCartItem temp = new ShoppingCartItem {
            ProductId = cart.ProductId, Quantity = cart.Quantity
        };

        if (!myCart.FindProduct(temp))
        {
            myCart.AddCart(cart);
        }

        //added additionally
        Session["MyCart"] = myCart;

        Server.Transfer("~/Modules/aspx/MyCart.aspx");
    }
Exemplo n.º 2
0
    /// <summary>
    /// items to be added to database
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AddToCartLinkButton_Click(object sender, EventArgs e)
    {
        //RetreiveWishList();
        ShoppingCartItem cart = new ShoppingCartItem();
        GridViewRow      row  = ((Control)sender).NamingContainer as GridViewRow;
        GridView         grid = row.NamingContainer as GridView;

        //LOADCATEGORIES
        cart.ProductId   = grid.DataKeys[row.RowIndex].Value.ToString();
        cart.ProductName = (row.FindControl("ProductLabel") as Label).Text;
        cart.UnitPrice   = decimal.Parse((row.FindControl("UnitPriceLabel") as Label).Text);
        cart.Quantity    = 1;
        cart.Total       = cart.UnitPrice * cart.Quantity;

        ShoppingCartItem temp = new ShoppingCartItem {
            ProductId = cart.ProductId, Quantity = cart.Quantity
        };

        if (!myCart.FindProduct(temp))
        {
            myCart.AddCart(cart);
        }

        Server.Transfer("~/Modules/aspx/MyCart.aspx");
    }
Exemplo n.º 3
0
    private void AddToCart(ShoppingCartItem cart)
    {
        cart.ProductId   = ProductFormView.DataKey[0].ToString();
        cart.ProductName = (ProductFormView.Row.FindControl("ProductLabel") as Label).Text;
        cart.UnitPrice   = decimal.Parse((ProductFormView.Row.FindControl("UnitPriceLabel") as Label).Text);
        TextBox quantityTextBox = ProductFormView.Row.FindControl("QuantityTextBox") as TextBox;

        if (quantityTextBox.Text.Equals(string.Empty))
        {
            cart.Quantity = 1;
        }
        else
        {
            cart.Quantity = int.Parse(quantityTextBox.Text);
        }
        cart.Total = cart.UnitPrice * cart.Quantity;

        ShoppingCartItem temp = new ShoppingCartItem {
            ProductId = cart.ProductId, Quantity = cart.Quantity
        };

        if (!myCart.FindProduct(temp))
        {
            myCart.AddCart(cart);
        }

        Session["MyCart"] = myCart;

        Server.Transfer("~/Modules/aspx/MyCart.aspx");
    }
Exemplo n.º 4
0
        public ActionResult AddToCart(AlbumViewModel album)
        {
            MyCart            cart     = Session["cart"] as MyCart;
            CartItemViewModel cartItem = new CartItemViewModel();

            cartItem.ID     = album.AlbumID;
            cartItem.Name   = album.Title;
            cartItem.Price  = album.Discounted ? album.Price * 0.9m : album.Price;
            cartItem.Amount = 1;
            cart.AddCart(cartItem);
            Session["cart"] = cart;
            return(PartialView("_CartButton"));
        }
Exemplo n.º 5
0
        public IActionResult AddToCart([FromBody] CartVM cart)
        {
            MyCart   sepet    = HttpContext.Session.Get <MyCart>("cart");
            CartItem cartItem = new CartItem();

            cartItem.ID     = cart.ID;
            cartItem.Name   = cart.Name;
            cartItem.Price  = cart.Price;
            cartItem.Amount = 1;
            sepet.AddCart(cartItem);
            HttpContext.Session.Set <MyCart>("cart", sepet);
            return(PartialView("_cartButton", sepet.TotalAmount));
        }
        public IActionResult AddCartItem([FromBody] CartVM cartVM)
        {
            MyCart   myCart    = HttpContext.Session.Get <MyCart>("cart");
            CartItem addedCart = new CartItem
            {
                ID     = cartVM.ID,
                Name   = cartVM.Name,
                Price  = cartVM.Price,
                Amount = 1
            };

            myCart.AddCart(addedCart);
            HttpContext.Session.Set("cart", myCart);
            return(PartialView("_cartButton", myCart.TotalAmount));
        }
Exemplo n.º 7
0
        public ActionResult AddToCart(int id)
        {
            MyCart            cart     = Session["cart"] as MyCart;
            CartItemViewModel cartItem = new CartItemViewModel();
            var eklenenAlbum           = _albumService.Get(id);

            cartItem.ID     = eklenenAlbum.ID;
            cartItem.Name   = eklenenAlbum.Title;
            cartItem.Price  = eklenenAlbum.Discounted ? eklenenAlbum.Price * 0.9m : eklenenAlbum.Price;
            cartItem.Amount = 1;

            cart.AddCart(cartItem);
            Session["cart"] = cart;

            return(PartialView("_CartButton"));
        }
Exemplo n.º 8
0
        public ActionResult AddToCart(int id)
        {
            //MyCartı session içindeki karta eşitliyoruz.
            MyCart            cart     = Session["cart"] as MyCart;
            CartItemViewModel cartItem = new CartItemViewModel();
            var eklenenUrun            = _productService.Get(id); //Eklenen albümü bul. Sepete ekleye basınca o ID ye ait ürünü bulması için

            //CartItem ın özelliklerine eşitle
            cartItem.ID     = eklenenUrun.ID;
            cartItem.Name   = eklenenUrun.Title;
            cartItem.Price  = eklenenUrun.Price;
            cartItem.Amount = 1;
            //Session dan oluşturduğum carta ekliyorum
            cart.AddCart(cartItem);
            Session["cart"] = cart;
            return(PartialView("_CartButton")); //Sepet içindeki ürün sayısını dönmesi için
        }