Ejemplo n.º 1
0
        // https://prod.liveshare.vsengsaas.visualstudio.com/join?11520D56B900E64EF9597DAA2A347C8D6C89
        public async Task <JsonResult> AddJS(int id)
        {
            Clothing c = await ClothingDB.GetClothingById(id, _context);

            // TODO: add item to cart
            if (c == null)
            {
                // return item not found message (404)
                JsonResult notFound = new JsonResult("Not Found");
                notFound.StatusCode = 404;
                return(notFound);
            }

            var item = new ClothingCartViewModel()
            {
                ItemId    = c.ItemID,
                Title     = c.Title,
                Price     = c.Price,
                DateAdded = DateTime.Now
            };

            CartHelper.Add(item, _http);

            // TODO: send success response
            JsonResult result = new JsonResult("Item Added");

            result.StatusCode = 200; // HTTP okay

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ConfirmDelete(int id)
        {
            Clothing c = await ClothingDB.GetClothingById(id, _context);

            await ClothingDB.Delete(c, _context);

            TempData["Message"] = $"{c.Title}, ID#: {c.ItemID}, Deleted Successfully";
            return(RedirectToAction(nameof(ShowAll)));
        }
Ejemplo n.º 3
0
        // Add a single item to the shopping cart
        public async Task <IActionResult> Add(int id, string prevUrl)
        {
            Clothing c = await ClothingDB.GetClothingById(id, _context);

            if (c != null)
            {
                CartHelper.Add(c, _http);
            }

            return(Redirect(prevUrl));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Delete(int id)
        {
            Clothing c = await ClothingDB.GetClothingById(id, _context);

            if (c == null)
            {
                return(NotFound());
            }

            return(View(c));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }
            Clothing c = await ClothingDB.GetClothingById(id.Value, _context);

            if (c == null)
            {
                // HTTP 404 Not Found
                return(NotFound());
            }


            return(View(c));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add a single product to the cart.
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> Add(int id, string prevUrl)
        {
            Clothing c = await ClothingDB.GetClothingById(id, _context);

            if (c != null)
            {
                var item = new ClothingCartViewModel()
                {
                    ItemId    = c.ItemID,
                    Title     = c.Title,
                    Price     = c.Price,
                    DateAdded = DateTime.Now
                };
                CartHelper.Add(item, _http);
            }

            TempData["Message"] = $"{c.Title}, ID#: {c.ItemID}, Added Successfully";
            //return RedirectToAction("Index", "Home");
            return(Redirect(prevUrl));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Edit(int?id) // changed parameter to nullable
        {
            if (id == null)
            {
                // HTTP 400 error
                return(BadRequest());
            }

            // pass primary key value, like canvas
            Clothing c = await ClothingDB.GetClothingById(id.Value, _context); // .Value added when parameter was changed to nullable

            if (c == null)                                                     // item not in DB
            {
                return(NotFound());                                            // returns HTTP 404 - Not Found Error

                //return RedirectToAction("ShowAll");
                //viewdata, item not found in db
            }

            return(View(c));
        }