public void CreateCart(Cartitem cartitem) { using (var connection = new MySqlConnection(this.connectionString)) { connection.Execute("INSERT INTO Carts (Id) VALUES (@cart_id)", cartitem); } }
public ActionResult DeleteConfirmed(int id) { Cartitem cartitem = db.Cartitems.Find(id); db.Cartitems.Remove(cartitem); db.SaveChanges(); return(RedirectToAction("Index")); }
public int GetPromotionAppliedAmountForSkuB(Cartitem cartitem) { int amount = 0; int remainigQuantity; int promotionQuantity = Math.DivRem(cartitem.Quantity, PromotionQuantity.KsuBPromotionQuantity, out remainigQuantity); amount = (promotionQuantity * 45) + (remainigQuantity * 30); return(amount); }
public void DisplayCart() { lstCart.Items.Clear(); for (int i = 0; i < itemList.Count(); i++) { Cartitem itemToDisplay = itemList.itemAt(i); lstCart.Items.Add(itemToDisplay.Display()); } }
protected void btnAdd_Click(object sender, EventArgs e) { Cartitem myCartItem = new Cartitem(selectedProduct, Convert.ToInt32(txtQuantity.Text)); lblTotal.Text = "Purchasing " + myCartItem.Quantity + " " + myCartItem.Product.Name; Session["CartItem"] = myCartItem; //pass this to cart aspxcs //Server.Transfer("Cart.aspx.cs"); }
public bool Add(Cartitem cartitem) { if (true) { using (var connection = new MySqlConnection(this.connectionString)) { connection.Execute("INSERT INTO Cartitems (cart_id, product_id) VALUES(@cart_id, @product_id)", cartitem); } } return(false); }
public IActionResult Post([FromBody] Cartitem cartitem) { var result = this.cartitemService.Add(cartitem); if (!result) { return(BadRequest()); } return(Ok()); }
public ActionResult Edit([Bind(Include = "Id,Quantity,CartitemTotal,ProductId")] Cartitem cartitem) { if (ModelState.IsValid) { db.Entry(cartitem).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", cartitem.ProductId); return(View(cartitem)); }
public bool Add(Cartitem cartitem) { if (cartitem.product_id <= 0) { return(false); } if (cartitem.cart_id <= 0) { return(false); } this.cartsRepository.Add(cartitem); return(true); }
// GET: Cartitems/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Cartitem cartitem = db.Cartitems.Find(id); if (cartitem == null) { return(HttpNotFound()); } return(View(cartitem)); }
// GET: Cartitems/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Cartitem cartitem = db.Cartitems.Find(id); if (cartitem == null) { return(HttpNotFound()); } ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", cartitem.ProductId); return(View(cartitem)); }
//update cart item public ActionResult UpdateCartitem(int id, FormCollection q) { Book b = db.Books.SingleOrDefault(x => x.book_Id == id); if (b == null) { return(RedirectToAction("Index", "Home")); } List <Cartitem> listCartitem = GetCartitem(); Cartitem product = listCartitem.SingleOrDefault(n => n.book_Id == id); if (product != null) { product.book_Quantity = int.Parse(q["txtQuantity"].ToString()); } return(RedirectToAction("Cart")); }
public IActionResult Post([FromBody] Cartitem cartitem) { var result = this.cartsService.Add(cartitem); if (!result) { return(BadRequest()); } var cartResults = this.cartsService.GetCart(cartitem.cart_id); if (cartResults == null) { this.cartsService.CreateCart(cartitem); } return(Ok()); }
public ActionResult AddItem(long productId, int quantity) { var product = new ProductDao().ViewDetail(productId); var cart = Session[CartSession]; if (cart != null) { var list = (List <Cartitem>)cart; if (list.Exists(x => x.Product.ID == productId)) { foreach (var item in list) { if (item.Product.ID == productId) { item.Quantity += quantity; } } } else { // tạo mới đối tượng cart item var item = new Cartitem(); item.Product = product; item.Quantity = quantity; list.Add(item); } // gán vào session Session[CartSession] = list; } else { // tạo mới đối tượng cart item var item = new Cartitem(); item.Product = product; item.Quantity = quantity; var list = new List <Cartitem>(); list.Add(item); // gán vào session Session[CartSession] = list; } return(RedirectToAction("Index")); }
//private Cartitem itempass; protected void Page_Load(object sender, EventArgs e) { //how can I receive information from btnAdd_Click from order page //Page lastPage = (Page)Context.Handler; myCartItem = (Cartitem)Session["Cartitem"]; //Validate that there are items within the cart if (myCartItem != null) { //write out what is being purchased lstCart.Items.Add(myCartItem.Display()); string itemString = "Purchasing" + myCartItem.Quantity.ToString() + "" + myCartItem.Product.Name; lstCart.Items.Add(itemString); } else { lstCart.Items.Add("Please add an item into the cart."); } }
//delete Cart item public ActionResult DeleteCartitem(int id, string slug) { Book b = db.Books.SingleOrDefault(x => x.book_Id == id); if (b == null) { return(RedirectToAction("Index", "Home")); } List <Cartitem> listCartitem = GetCartitem(); Cartitem product = listCartitem.SingleOrDefault(n => n.book_Id == id); if (product != null) { listCartitem.RemoveAll(n => n.book_Id == id); } if (listCartitem.Count == 0) { return(RedirectToAction("Index", "Home")); } return(RedirectToAction("Cart")); }
public ActionResult AddItem(int IDSach, int SoLuong) { var sach = new SachClientDao().ViewDetail(IDSach); var cart = Session[CartSession]; if (cart != null) { var list = (List <Cartitem>)cart; if (list.Exists(x => x.Sach.IDSach == IDSach)) { foreach (var item in list) { if (item.Sach.IDSach == IDSach) { item.SoLuong += SoLuong; } } } else { var item = new Cartitem(); item.Sach = sach; item.SoLuong = SoLuong; list.Add(item); } Session[CartSession] = list; } else { //tạo mới dối tượng cart item var item = new Cartitem(); item.Sach = sach; item.SoLuong = SoLuong; var list = new List <Cartitem>(); list.Add(item); //Gán vào session Session[CartSession] = list; } return(RedirectToAction("Index")); }
//Add cart items public ActionResult AddCartitem(string url, int id) { Book b = db.Books.SingleOrDefault(x => x.book_Id == id); if (b == null) { return(RedirectToAction("Index", "Home")); } List <Cartitem> listCartitem = GetCartitem(); //kiem tra book co ton tai trong session gio hang ko Cartitem product = listCartitem.Find(n => n.book_Id == id); if (product == null) { product = new Cartitem(id); listCartitem.Add(product); return(Redirect(url)); } else { product.book_Quantity++; return(Redirect(url)); } }
// Add a product to the cart. public ActionResult addtocart(int id) { var product = db.Products.Find(id); var cartViewModel = new CartViewModel(); ICollection <Cartitem> cartItemList; Cart cart; string sessionId = System.Web.HttpContext.Current.Session.SessionID; // Check if the current user has a cart object connected to his sessionid. var existingCart = from c in db.Carts where c.SessionId == sessionId && c.State == "active" select c; // If the current user doesn't have a cart ... if (!existingCart.Any()) { cart = new Cart(); cart.SessionId = sessionId; cart.State = "active"; if ((System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { cart.UserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); } cartItemList = new List <Cartitem>(); var Cartitem = new Cartitem(); Cartitem.ProductId = id; Cartitem.Quantity = 1; Cartitem.CartitemTotal = product.Price; cart.Total = Cartitem.CartitemTotal; db.Cartitems.Add(Cartitem); cartItemList.Add(Cartitem); cart.Cartitems = cartItemList; db.Carts.Add(cart); db.SaveChanges(); cartViewModel.Cart = cart; cartViewModel.Cartitems = cart.Cartitems; } // If the current user does have a cart ... else { cart = existingCart.First(); if ((System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { cart.UserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); } cartItemList = cart.Cartitems; // Check if there already is a cartitem with this product id. var checkCartitem = from c in db.Cartitems where c.ProductId == id && c.CartId == cart.Id select c; // If the product is not in the cart ... if (!checkCartitem.Any()) { var Cartitem = new Cartitem(); Cartitem.ProductId = id; Cartitem.Quantity = 1; Cartitem.CartitemTotal = product.Price; cart.Total += Cartitem.CartitemTotal; db.Cartitems.Add(Cartitem); cartItemList.Add(Cartitem); cart.Cartitems = cartItemList; db.SaveChanges(); cartViewModel.Cart = cart; cartViewModel.Cartitems = cart.Cartitems; } //If the product is already in the cart put a message out and stay on the // product page. else { return(RedirectToAction("Index")); } } //cart = db.Carts.Find(cart.Id); //var cartItems = from c in db.Cartitems // where c.Cart.Id == cart.Id // select c; //cartViewModel.Cart = cart; //cartViewModel.Cartitems = cartItems.ToList(); //return RedirectToAction("CartIndex", "Carts"); return(View("~/Views/Carts/CartIndex.cshtml", cartViewModel)); }
public void CreateCart(Cartitem cartitem) { this.cartsRepository.CreateCart(cartitem); }