public ActionResult AddItem(int id, int quantity = 1) { AppUser user = GetCurrentUser(); if (user == null) { return(View("_Error", new string[] { GetErrorMessage.NullUser })); } Product product = _productRepository.GetById(id); Cart cart = _cartRepository.GetCurrentCart(user); if (product.NumberInStock > 0) { product.NumberInStock -= quantity; _cartRepository.AddItem(cart, product, quantity); _unitOfWork.SaveChanges(); } else { return(View("_Error", new string[] { "Product out of stock!" })); } return(RedirectToAction("Details")); }
public async Task <IActionResult> OnPostAddToCartAsync(int productId) { //if (!User.Identity.IsAuthenticated) // return RedirectToPage("./Account/Login", new { area = "Identity" }); await _cartRepository.AddItem("test", productId); return(RedirectToPage("Cart")); }
private void MockCart() { Guid id = new Guid("64d9cb37-eb78-46b8-8ab8-115c0c6a0547"); _cartRepository.Create(id); var product = _productRepository.GetAsync("High Heel"); _cartRepository.AddItem(id, product.Result); }
public bool AddItem(int customerID, int productDetailID, int orderNo) { Cart cart = new Cart() { CustomerID = customerID, ProductDetailID = productDetailID, orderBy = orderNo, status = "on process" }; return(_cartRepository.AddItem(cart)); }
public async Task <ActionResult> AddToCart(int productId, decimal quantity, string returnUrl) { //Find a product with the given Id from the parameters Products product = _repository.Products.SingleOrDefault(x => x.ProductId == productId); if (product != null) { // if you add to cart from product view, add it with quantity 1 instead of 0 if (quantity == 0) { quantity = 1; } await _cartRepository.AddItem(product, quantity, _userManager.GetUserId(User)); } return(Redirect("Index")); }
public void AddItem(Product product) { CartLine line = _repo.GetByCode(product.Code); if (line == null) { _repo.AddItem(new CartLine { Product = product, Quantity = 1 }); } else { line.Quantity += 1; } }
public RedirectToRouteResult AddToCart(Cart cart, Guid Id, string returnUrl) { Product product = _productRepository.Products.FirstOrDefault(x => x.Id == Id); cart = HttpContext.Session["Cart"] as Cart; if (cart == null) { cart = new Cart(); // _cartRepository.SaveCart(cart); } //cart = HttpContext.Session["Cart"] as Cart ?? new Cart(); if (product != null) { _cartRepository.AddItem(cart, product, 1); //cart.AddItem(product, 1); HttpContext.Session["Cart"] = cart; } return(RedirectToAction("Index", new { returnUrl })); }
public void AddItem(CartItemViewModel ci) { var myItem = _mapper.Map <CartItemViewModel, CartItem>(ci); _cartRepo.AddItem(myItem); }
public async Task AddAsync(Guid id, string productName) { var product = await _productRepository.GetAsync(productName); await _repository.AddItem(id, product); }
//добавить предмет в корзину [добавить новую запись в CartLine] public void AddItemToCart(int userID, int ProductId) { var cartId = _cartRepository.GetUserCartId(userID); // ID карзины для User _cartRepository.AddItem(ProductId, cartId, 1); // добавляем новую запись в CartLine }
public RedirectToRouteResult AddToCart(int productID, string returnUrl) { repository.AddItem(productID, 1); return(RedirectToAction("Index", new { returnUrl })); }
public void AddItem(Product product, int quantity) { _cartRepositiry.AddItem(product, quantity); }