public static int AddCart(CartInfo cart, int userID) { if (userID > 0) { cart.ID = dal.AddCart(cart); } else { cart.ID = CartHelper.AddToCart(cart); } return(cart.ID); }
private void Fruit_Click(object sender, EventArgs e) { Button btn = (Button)sender; IItem item = new Fruit(btn.Text); cartFruit.AddCart(item); ShowCrat(labelFruit, cartFruit.GetCartText); }
public ActionResult AddToCart(int productID, int productQuantity) { Product product = new Product() { ProductID = productID, Quantity = productQuantity }; var res = icart.AddCart(product, userId); if (res == "Success") { this.Flash(Toastr.SUCCESS, "Alert", "Item Aded to Cart"); } else { this.Flash(Toastr.SUCCESS, "Alert", "Error adding Item"); TempData["Success"] = "An Error Occured"; } return(RedirectToAction("Index", "Shop")); }
//public Cart Pay(int? id, DateTime datetime, int ID) //{ // var pay = icart.Pay(id,datetime,ID); // return pay; //} public void AddCart(int userid, int goodsid, int count, DateTime carttime, double price, int flag) { icart.AddCart(userid, goodsid, count, carttime, price, flag); }
public IActionResult Store(int id, int quantity) { if (HttpContext.Session.GetString("Username") == null) { return(RedirectToAction("Login", "Home")); } else { var currentProduct = _product.GetById(id); if (currentProduct.Available == false) { HttpContext.Session.SetString("ERRORPRODUCT", "Sản phảm " + currentProduct.Name + " bạn muốn mua hiện đã hết hàng"); return(RedirectToAction("List")); } else { HttpContext.Session.Remove("ERRORPRODUCT"); if (quantity != 0 || quantity != 1) { String userId = HttpContext.Session.GetString("Username"); var cart = _cart.GetCartByUser(userId, id); if (cart != null) { cart.Quantity += quantity; _cart.UpdateCart(cart); } else { cart = new Cart(); cart.Product = _product.GetById(id); cart.Quantity = quantity; // cart.Id = id; cart.UserId = userId; DateTime date = Convert.ToDateTime(DateTime.Now); cart.DateBuy = date; _cart.AddCart(cart); } } else { // ListCart = new List<Cart>(); String userId = HttpContext.Session.GetString("Username"); var cart = _cart.GetCartByUser(userId, id); if (cart != null) { cart.Quantity++; _cart.UpdateCart(cart); } else { cart = new Cart(); cart.Product = _product.GetById(id); cart.Quantity = 1; // cart.Id = id; cart.UserId = userId; DateTime date = Convert.ToDateTime(DateTime.Now); cart.DateBuy = date; _cart.AddCart(cart); } } return(RedirectToAction("List")); } } }
public static void AddCart(Cart carts) { cartss.AddCart(carts); }