/// <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)
        {
            // grab item from db
            Product p = await _context.Products.FirstOrDefaultAsync(p => p.ProductId == id);

            CookieHelper.AddItemToCart(_httpContext, p);

            TempData["Message"] = $"{p.Title} added successfully!";

            // redirect them back to index
            return(Redirect(prevUrl));
        }
Beispiel #2
0
        /// <summary>
        /// dds 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)
        {

            // grab item from db
            Product p = await ProductDB.GetProductByIdAsync(_context, id);

            CookieHelper.AddItemToCart(_httpContext, p);

            TempData["Message"] = $"{p.Title} added successfully!";

            // redirect them back to index
            return Redirect(prevUrl);
        }