public async Task <IActionResult> Delete(int id)
        {
            // Get product with corresponding id
            Product p = await ProductDb.GetProductAsync(_context, id);

            return(View(p));
        }
        public async Task <IActionResult> Delete(int id)
        {
            Product p =
                await ProductDb.GetProductAsync(_context, id);

            return(View(p));
        }
        public async Task <IActionResult> Edit(int id)
        {
            // Get product with corressponding id
            Product p = await ProductDb.GetProductAsync(_context, id);

            // Pass product to view
            return(View(p));
        }
Exemple #4
0
        /// <summary>
        /// Removes an item from the shopping cart
        /// </summary>
        /// <param name="id"> Id of the product to remove </param>
        public async Task <IActionResult> Remove(int id, string prevUrl)
        {
            Products p = await ProductDb.GetProductAsync(_context, id);

            CookieHelper.RemoveProductFromCart(_httpContext, p);

            // redirect to previous page
            return(Redirect(prevUrl));
        }
Exemple #5
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            Product p = await ProductDb.GetProductAsync(_context, id);

            await ProductDb.DeleteProductAsync(_context, p);

            TempData["Message"] = $"{p.Title} was deleted successfully";
            return(RedirectToAction("Index"));
        }
Exemple #6
0
        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));
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            Product p =
                await ProductDb.GetProductAsync(_context, id);

            _context.Entry(p).State = EntityState.Deleted;
            await _context.SaveChangesAsync();

            TempData["Message"] = $"{p.Title} was deleted";
            return(RedirectToAction("Index"));
        }
Exemple #8
0
        /// <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 product to shopping cart
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> Add(int id, string prevUrl) // Id of the produuct to add
        {
            //Get product from the database
            Product p = await ProductDb.GetProductAsync(_context, id);

            CookieHelper.AddProductToCart(_httpContext, p);

            //Add product successfull message
            TempData["Message"] = p.Title + "added successfully";

            // Redirectback to previous page
            return(RedirectToAction(prevUrl));
        }
        public async Task <IActionResult> Edit(int id)
        {
            // Get prodct with corresponding id
            Product p = await ProductDb.GetProductAsync(_context, id);

            //Product p2 = await _context
            //            .Products
            //            .Where(prod => prod.ProductId == id)
            //            .SingleAsync();

            // pass product to view
            return(View(p));
        }