public ActionResult Add_Cart(int selected, int pid) { pr = new ProductRepo(); ProductModel productModel = pr.GetProduct(pid); CartModel cartModel = new CartModel() { CustomerID = (int)Session["MyID"], ProductID = productModel.ProductID, Price = productModel.Price, Quantity = selected, TotalPrice = selected * productModel.Price }; bool b = cr.AddToCart(cartModel); TempData["Cart"] = "True"; return(RedirectToAction("ViewCart")); }
public void AddToCart(string userId, int bookId) { var contains = _cartRepo.Contains(userId, bookId); if (contains) { var item = _cartRepo.GetCartItemByIds(userId, bookId); item.Quantity += 1; _cartRepo.ChangeQuantity(item); } else { CartItem item = new CartItem { UserId = userId, BookId = bookId, Quantity = 1 }; _cartRepo.AddToCart(item); } }
public string AddToCart(string acc, int productId) { var cart = _cartRepo.GetCartByAcc(acc); bool isHave = true; foreach (var c in cart) { if (c.Product_Id == productId) { isHave = false; } } if (isHave) { _cartRepo.AddToCart(acc, productId); return("新增成功"); } else { return("已在購物車"); } }
public IActionResult AddToCart([Microsoft.AspNetCore.Mvc.FromBody] int id) { CartRepo.AddToCart(id); return(new OkResult()); }
public void AddToCart(string UserId, int BookId) { _cartRepo.AddToCart(UserId, BookId); }
public void AddToCart(BookListViewModel book, HttpContext context) { _cartRepo.AddToCart(book, context); }