示例#1
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            Clothing c = await ClothingDb.GetClothingById(id, _context);

            await ClothingDb.Delete(c, _context);

            TempData["Message"] = $"{c.Title} deleted successfully";
            return(RedirectToAction(nameof(ShowAll)));
        }
示例#2
0
        public async Task <IActionResult> DeleteConfirmed(int id) /*change the method name, still posting to delete, just calling a different method, work around*/
        {
            Clothing c = await ClothingDb.GetClothingById(id, _context);

            await ClothingDb.Delete(c, _context);

            TempData["Message"] = $"{c.Title} deleted successfully";
            return(RedirectToAction(nameof(ShowAll)));
        }
        // Add a single product to the shopping cart.
        public async Task <IActionResult> AddToCartAsync(int id, string prevUrl)
        {
            Clothing c = await ClothingDb.GetClothingById(id, _context);

            if (c != null)
            {
                CartHelper.Add(c, _http);
            }
            return(Redirect(prevUrl));
        }
示例#4
0
        public async Task <IActionResult> Delete(int id)
        {
            Clothing c = await ClothingDb.GetClothingById(id, _context);

            if (c == null) // If clothing does not exist
            {
                return(NotFound());
            }
            return(View(c));
        }
        public async Task <IActionResult> Delete(int id)
        {
            Clothing c = await ClothingDb.GetClothingById(id, _context);

            if (c == null) //if clothing is not in the database
            {
                //returns a HTTP 404 - Not found error
                return(NotFound());
            }
            return(View(c));
        }
示例#6
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {   // HTTP 400
                return(BadRequest());
            }
            Clothing c = await ClothingDb.GetClothingById(id.Value, _context); // .Value gets value from a null

            if (c == null)                                                     // Clothing not in DB
            {
                return(NotFound());                                            // Returns a HTTP 404 - Not Found
            }
            return(View(c));
        }
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                // HTTP 400
                return(BadRequest());
            }
            Clothing c = await ClothingDb.GetClothingById(id.Value, _context);

            if (c == null)          // Clothing item is not found in the DB
            {
                return(NotFound()); // returns a HTTP 404 - Not Found
                // return RedirectToAction("ShowAll"); // Returns the user to the ShowAll Page
            }

            return(View(c));
        }
        public async Task <JsonResult> AddJS(int id)
        {
            //Get id of clothing
            Clothing c = await ClothingDb.GetClothingById(id, _context);

            //Add clothing to the cart
            if (c == null)
            {
                //Return not found message
            }
            CartHelper.Add(c, _http);

            //Send success response
            JsonResult result = new JsonResult("Success");

            result.StatusCode = 200; //Http ok
            return(result);
        }
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null) //returns a HTTP 404 - Not found error
            {
                //HTTP 400
                return(BadRequest());
            }

            Clothing c = await ClothingDb.GetClothingById(id.Value, _context);

            if (c == null)
            {
                //returns a HTTP 404 - Not found error
                return(NotFound());
            }

            return(View(c));
        }
示例#10
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                // HTTP 400
                return(BadRequest());
            }
            Clothing c =
                await ClothingDb.GetClothingById(id.Value, _context); //context is a field in the controller, hence _context

            if (c == null)                                            // Clothing not in the DB
            {
                // RETURNS A HTTP 404 - nOT FOUND
                return(NotFound());
                //Redirects to page
                //return RedirectToAction("ShowAll");
            }

            return(View(c));
        }