/// <summary> /// Add to Cart method /// </summary> /// <param name="Page">page you are coming from</param> /// <param name="index">index of item to be added</param> /// <returns></returns> public ActionResult ATC(string Page, int index) { //If user is logged in otherwise no adding if (Session["UserId"] != null) { //Filling the cart from its JSON StoreFront.CustomerCart = Models.Files.WorkingWithJSON <Models.Cart.CartItem> .GetCartData((int)(Session["UserId"]), 0); //If that file was empty or did not exsist give a brand new customer cart if (StoreFront.CustomerCart == null) { StoreFront.CustomerCart = new List <Models.Cart.CartItem>(); } //Finds item based on its id and if it matches the index of the item sougt after Models.StoreItem.Furniture item = StoreFront.StoreStock.Find(x => x.id == index); //Makes furniture object into Cartitems Models.Cart.CartItem cartItem = new Models.Cart.CartItem((int)item.id, item.Name, item.Price, 1, item.ImageLink, item.Room) { //Adds the stock since it is not part of the constructor Stock = item.Stock }; //Atempt to put item in cart Models.Cart.CartItem.AddToCart(cartItem, StoreFront.CustomerCart); //create or change the Session variable used later Session["Count"] = StoreFront.CustomerCart.Count; //Saves new data Models.Files.WorkingWithJSON <Models.Cart.CartItem> .SaveCartData(StoreFront.CustomerCart, (int)(Session["UserId"])); } return(RedirectToAction("Index", Page)); }
private bool AddProduct(Product product) { var cartItem = new Models.Cart.CartItem() { Id = product.Id, Name = product.Name, Price = product.Price, Quantity = 1 }; this.cartItems.Add(cartItem); return(true); }
private bool AddProduct(Product.Product pProduct) { var cartItem = new Models.Cart.CartItem() { Id = pProduct.Id, Name = pProduct.Name, Price = pProduct.Price, DefaultImageURL = pProduct.DefaultImageURL, Quantity = 1 }; this.Items.Add(cartItem); return(true); }
private bool AddProduct(Product product) { var cartItem = new Models.Cart.CartItem() { Id = product.Id, Name = product.Name, Price = product.ProductPrices.ToList()[0].Price, DefaultImageURL = product.ProductAssets.ToList()[0].ImageUri, Quantity = 1 }; //加入CartItem至購物車 this.cartItems.Add(cartItem); return(true); }
//新增商品至購物車 private bool AddProduct(Product project) { var cartItem = new Models.Cart.CartItem() { Id = project.Id, Name = project.Name, Price = project.Price, Quantity = 1, DefaultImageURL = project.DefaultImageURL }; // 加入CartItem至購物車 this.cartItems.Add(cartItem); return(true); }
//加入購物車 private bool AddProduct(Product product) { var cartItem = new Models.Cart.CartItem() { produtctId = product.productID, productName = product.productName, price = product.productPrice, picture = product.productPicture, stoteName = product.Store.storeName, note = "", quantity = 1, }; this.cartItemList.Add(cartItem); return(true); }
//新增一筆Product,使用Product物件 private bool AddProduct(product product, int quantity) { //將Product轉為CartItem var cartItem = new Models.Cart.CartItem() { Id = product.productid, Name = product.productname, Price = product.unitprice, Quantity = quantity, sell_id = product.user_email, category = product.category }; //加入CartItem至購物車 this.cartItems.Add(cartItem); return(true); }