private async Task <int> GetMaxPage(int PageSize) { int numProducts = await ClothingDB.GetNumClothing(_context); return(Convert.ToInt32( Math.Ceiling((double)numProducts / PageSize))); }
// 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); }
public async Task <IActionResult> DeleteComfirmed(int id) { Clothing c = await ClothingDB.GetClothingbyID(id, _context); await ClothingDB.Delete(id, _context); TempData["Message"] = $"{c.Title} deleted successfully"; return(RedirectToAction(nameof(ShowAll))); }
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))); }
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(InventoryList))); }
public async Task <IActionResult> Edit(Clothing c) { if (ModelState.IsValid) { await ClothingDB.Edit(c, _context); ViewData["Message"] = $"{c.Title} updated successfully"; return(View(c)); } return(View(c)); }
public async Task <IActionResult> Delete(int id) { Clothing c = await ClothingDB.GetClothingById(id, _context); if (c == null) { return(NotFound()); } return(View(c)); }
// Add a single product 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, _accessor); } return(Redirect(prevUrl)); }
// Add a single product 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); } // Use Redirect instead of RedirectToAction because prevUrl doesn't have an action tied to it return(Redirect(prevUrl)); }
public async Task <IActionResult> Delete(int ID) { Clothing c = await ClothingDB.GetClothingByID(ID, _context); if (c == null) { // returns a HTTP 404 error - Not Found return(NotFound()); } return(View(c)); }
public async Task <IActionResult> Add(Clothing c) { if (ModelState.IsValid) { await ClothingDB.Add(c, _context); // TempData lasts for one redirect TempData["Message"] = $"{c.Title} added successfully"; return(RedirectToAction("ShowAll")); } //Return same view with error messages return(View(c)); }
public async Task <IActionResult> Add(Clothing c) // Asynchronous Method { if (ModelState.IsValid) { await ClothingDB.Add(c, _context); // TempData lasts for one redirect, stays in memory TempData["Message"] = $"{c.Title} Added Successfully"; return(RedirectToAction("ShowAll")); } // return same view with validation error messages return(View(c)); }
public async Task <IActionResult> InventoryList(int?page) { const int PageSize = 2; // Null coalescing operator int pageNumber = page ?? 1; ViewData["CurrentPage"] = pageNumber; ViewData["MaxPage"] = await GetMaxPage(PageSize); List <Clothing> clothes = await ClothingDB.GetClothingByPage(_context, pageNum : pageNumber, pageSize : PageSize); return(View(clothes)); }
public async Task <IActionResult> Edit(Clothing c) { if (ModelState.IsValid) { await ClothingDB.Edit(c, _context); //return View(c); TempData["Message"] = $"{c.Title}, ID#: {c.ItemID}, Updated Successfully"; // TempData lasts for one redirect, stays in memory return(RedirectToAction("ShowAll")); //return Redirect(prevUrl); } return(View(c)); }
public async Task <IActionResult> Add(Clothing c) { if (ModelState.IsValid) { await ClothingDB.Add(c, _context); // Temp data lasts for one redirect TempData["Message"] = $"{c.Title} added successfully"; return(RedirectToAction(nameof(InventoryList))); } else { //Return same view with validation messages return(View(c)); } }
public async Task <IActionResult> ShowAll(int?page) // method must begin with await, await req's async after public, and a task return.: ? is nullable { const int PageSize = 2; // default number of items per page //int pageNumber = page ?? 1; // null coalescing operator ?? (https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator) int pageNumber = page.HasValue ? page.Value : 1; // conditional statement ? ViewData["CurrentPage"] = pageNumber; int maxPage = await GetMaxPage(PageSize); // How many pages, always rounds up ViewData["MaxPage"] = maxPage; // put in view data so we can use it in our view List <Clothing> clothes = await ClothingDB.GetClothingByPage(_context, pageNum : pageNumber, pageSize : PageSize); return(View(clothes)); }
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)); }
public async Task <IActionResult> Search(SearchCriteria search) { if (ModelState.IsValid) { if (search.IsBeingSearched) { await ClothingDB.BuildSearchQuery(search, _context); } else { ModelState.AddModelError(string.Empty, "You must search by at least one criteria"); } return(View(search)); } return(View()); }
public async Task <IActionResult> ShowAll(int?page) { const int PageSize = 2; // Null-coalescing operator ?? // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator int pageNumber = page ?? 1; ViewData["CurrentPage"] = pageNumber; int maxPage = await GetMaxPage(PageSize); ViewData["MaxPage"] = maxPage; List <Clothing> clothes = await ClothingDB.GetClothingbyPage(_context, pageNumber, PageSize); return(View(clothes)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(BadRequest()); } //Return same view with validation messages Clothing c = await ClothingDB.GetClothingbyID(id.Value, _context); if (c == null) // Clothing not in DB { // Returns a HTTP 404 - Not Found return(NotFound()); } 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); // .Value can extract data out of a nullable data type if (c == null) // Clothing not in DB { // returns a HTTP 404 error - Not Found return(NotFound()); } return(View(c)); }
public async Task <IActionResult> Search(SearchCriteria search) { if (ModelState.IsValid) { if (search.IsBeingSearched()) { await ClothingDB.Search(search, _context); return(View(search)); } else { ModelState.AddModelError(string.Empty, "You must search by at least 1 criteria. Otherwise, why are you even here?"); return(View(search)); } } return(View()); }
public async Task <IActionResult> Search(SearchCriteria search) { if (ModelState.IsValid) { if (search.IsSearchBeingPerformed()) { //Not yet sent to DB search = await ClothingDB.BuildSearchQuery(search, _context); return(View(search)); } else { ModelState.AddModelError(string.Empty, "You must search by at least one criteria"); return(View(search)); } } return(View()); }
/// <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)); }
public async Task <IActionResult> Search(SearchCriteria sc) { // Could we use a button click event to do nothing until the button is clicked? if (ModelState.IsValid) { if (sc.IsBeingSearched()) { await ClothingDB.BuildSearchQuery(sc, _context); return(View(sc)); } else { ModelState.AddModelError(string.Empty, "Please enter search criteria"); return(View(sc)); } } return(View()); }
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)); }
public async Task <IActionResult> Delete(int id) { Clothing c = await ClothingDB.GetClothingbyID(id, _context); return(View(c)); }