/// <summary> /// Adds a product to the shopping cart /// </summary> /// <param name="id">The id of the product to add</param> /// <returns></returns> public async Task <IActionResult> Add(int id) { Product p = await ProductDb.GetSingleProductAsync(_context, id); CookieHelper.AddProductToCart(_httpContext, p); // Redirect back to previous page return(RedirectToAction("Index", "Product")); }
/// <summary> /// Adds an item to the shopping cart /// </summary> /// <param name="id"> Id of the product to add </param> public async Task <IActionResult> Add(int id, string prevUrl) { Products p = await ProductDb.GetProductAsync(_context, id); CookieHelper.AddProductToCart(_httpContext, p); // redirect to previous page return(Redirect(prevUrl)); }
/// <summary> /// Adds a product to the shopping cart /// </summary> /// <param name="id">The id of the product to add</param> /// <returns></returns> public async Task <IActionResult> Add(int id) // Id of the product to add { // Get product from the DB Product p = await ProductDb.GetProductByIdAsync(_context, id); CookieHelper.AddProductToCart(p, _httpContext); // Redirect back to previous page return(RedirectToAction("Index", "Product")); }
/// <summary> /// Adds a Product to the shopping cart /// </summary> /// <param name="id">The ID of the product</param> /// public async Task <IActionResult> Add(int id, string prevURL) { Product p = await ProductDB.GetProductAsync(_context, id); CookieHelper.AddProductToCart(_httpContext, p); //must use tempData in order to redirect successfully with a message. TempData["Message"] = p.Title + " added successfully"; return(Redirect(prevURL)); }
public async Task <IActionResult> Add(int id, string prevUrl) { Product p = await ProductDb.GetProductAsync(_context, id); CookieHelper.AddProductToCart(_httpContext, p); TempData["Message"] = p.Title + " added successfully"; // Redirect back to previous page return(Redirect(prevUrl)); }
/// <summary> /// Add a product to the shopping cart /// </summary> /// <param name="id">The id of the product to add</param> /// <returns></returns> public async Task <IActionResult> Add(int id, string previosUrl) // Id of the product to add { // Get product from the database Product p = await ProductDB.GetProductAsync(_context, id); CookieHelper.AddProductToCart(_httpContext, p); TempData["Message"] = p.Title + " was added successfully"; // redirct back to prevoius page return(Redirect(previosUrl)); }
/// <summary> /// Add the product to the shopping cart /// </summary> /// <param name="id">ProductId</param> /// <returns></returns> public async Task <IActionResult> Add(int id, string prevUrl) // id of product to add, previous url { // get product from data base Product p = await ProductDb.GetProductAsync(_context, id); CookieHelper.AddProductToCart((HttpContextAccessor)_httpContext, p); TempData["Message"] = p.Title + " added successfully"; // redirect to previous page return(Redirect(prevUrl)); }
/// <summary> /// Adds a product to the shopping cart /// </summary> /// <param name="id">The Id of the product to store</param> /// <returns></returns> public async Task <IActionResult> Add(int id, string prevUrl) // Id of the product to add { // Get from DB Product p = await ProductDb.GetProductAsync(_context, id); CookieHelper.AddProductToCart(_httpContext, p); TempData["Message"] = $"{p.Title} added to the cart successfully"; // redirect back to the same page of catalog return(Redirect(prevUrl)); }
/// <summary> /// Adds a product to the shopping cart /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <IActionResult> Add(int id, string prevUrl) // Id of product to add to the cart { // Get product from database Product p = await ProductDb.GetProductAsync(_context, id); // Add product to cart CookieHelper.AddProductToCart(_httpContext, p); TempData["Message"] = p.Title + " added successfully"; // Redirect back to previous page return(Redirect(prevUrl)); }
/// <summary> /// Adds a product to the shopping cart /// </summary> /// <param name="id">The id of the product to add</param> /// <returns></returns> public async Task <IActionResult> Add(int id, string prevUrl) { // Get product from the database Product p = await ProductDB.GetProductAsync(_context, id); List <Product> cartProducts = CookieHelper.GetCartProducts(_httpContext); CookieHelper.AddProductToCart(_httpContext, p); TempData["Message"] = $"{p.Title} was added to your cart"; // Redirect back to previous page return(Redirect(prevUrl)); }
/// <summary> /// Adds item to visited list /// </summary> /// <param name="id"></param> /// <param name="previosUrl"></param> /// <returns></returns> public async Task <IActionResult> AddVisited(int id, string previosUrl) { // Get product from the database ParkModel p = await ParkDB.GetProductAsync(_context, id); List <ParkModel> parks = CookieHelper.GetCartProducts(_httpContext); // stops same park from ebing added again if (parks.Contains(p)) { TempData["Message"] = p.ParkName + " was already added successfully"; } else { CookieHelper.AddProductToCart(_httpContext, p); TempData["Message"] = p.ParkName + " was added successfully"; } // redirct back to prevoius page return(Redirect(previosUrl)); }