public async Task <IActionResult> Update(int id) { VideoGame game = await VideoGameDb.GetGameById(id, _context); return(View(game)); }
public async Task <IActionResult> Index() { List <VideoGame> allGames = await VideoGameDb.GetAllGames(_context); return(View(allGames)); }
public async Task <IActionResult> DeleteConfirmed(int id) { await VideoGameDb.DeleteById(id, _context); // Direct back to the index return(RedirectToAction("Index")); }
public async Task <IActionResult> Update(int id) { //Get the single video game out of the db VideoGame game = await VideoGameDb.GetGameById(id, _context); return(View(game)); }
public async Task <IActionResult> Search(SearchCriteria criteria) { if (ValidSearch(criteria)) { criteria.GameResults = await VideoGameDb.Search(_context, criteria); } return(View(criteria)); }
public async Task <IActionResult> Search(SearchCriteria criteria) { if (ValidSearch(criteria)) //If it's a valid search { //Get an empty list or a populated list criteria.GameResults = await VideoGameDb.Search(_context, criteria); } return(View(criteria)); }
public async Task <IActionResult> Update(VideoGame g) { if (ModelState.IsValid) { await VideoGameDb.UpdateGame(g, _context); return(RedirectToAction("Index")); } return(View(g)); }
public async Task <IActionResult> Update(VideoGame g) { if (ModelState.IsValid) { await VideoGameDb.UpdateGame(g, _context); return(RedirectToAction("Index")); } // If there are any errors, show the user the form again return(View(g)); }
public async Task <IActionResult> Add(VideoGame game) { if (ModelState.IsValid) { await VideoGameDb.Add(game, _context); return(RedirectToAction("Index")); } // Return view with model including error messages return(View(game)); }
public async Task <IActionResult> Update(VideoGame g) { if (ModelState.IsValid) { //If it works update the game await VideoGameDb.UpdateGame(g, _context); //redirect to index return(RedirectToAction("Index")); } //If any erorrs show user form again return(View(g)); }
public async Task <IActionResult> Add(VideoGame game) { // model binding, if all data annotations validate if (ModelState.IsValid) { // add to database await VideoGameDb.Add(game, _context); return(RedirectToAction("Index")); } // if not valid: return view with model including error messages return(View(game)); }
public async Task <IActionResult> Search(SearchCriteria criteria) { if (ValidSearch(criteria)) { criteria.GameResults = await VideoGameDb.Search(_context, criteria); } //else //{ // // handle NullException() // criteria.GameResults = new List<VideoGame>(); //} // returns view with the given information return(View(criteria)); }
public async Task <IActionResult> Index(int?id) { // Null-coalescing operator // If id is not null set page to it, or if null use 1 int page = id ?? 1; // id is the page number coming in const int PageSize = 3; List <VideoGame> games = await VideoGameDb.GetGamesByPage(_context, page, PageSize); int totalPages = await VideoGameDb.GetTotalPages(_context, PageSize); ViewData["Pages"] = totalPages; ViewData["CurrentPage"] = page; return(View(games)); }
[HttpGet] // made id optional using ? public async Task <IActionResult> Index(int?id) { // id is the page number coming in // null-coalescing operator = if id is not null, set page to it. if null, use 1 int page = id ?? 1; const int PageSize = 3; List <VideoGame> games = await VideoGameDb.GetGamesByPage(_context, page, PageSize); int totalPages = await VideoGameDb.GetTotalPages(_context, PageSize); ViewData["Pages"] = totalPages; ViewData["CurrentPage"] = page; // the view as access to all of the data return(View(games)); }
public async Task <IActionResult> Index(int?id) { //Null-coalescing operator //id is the page number coming in int page = id ?? 1; //if the id is not null, it sets page to it. If it's null, use 1. const int PAGE_SIZE = 3; List <VideoGame> games = await VideoGameDb.GetGamesByPage(_context, page, PAGE_SIZE); int totalPages = await VideoGameDb.GetTotalPages(_context, PAGE_SIZE); ViewData["Pages"] = totalPages; ViewData["CurrentPage"] = page; return(View(games)); }
public async Task <IActionResult> Add(int id) { VideoGame g = await VideoGameDb.GetGameById(id, _context); CartHelper.Add(_httpAccessor, g); return(RedirectToAction("Index", "Library")); //// Set up cookie //CookieOptions options = new CookieOptions() //{ // Secure = true, // MaxAge = TimeSpan.FromDays(365) // A whole year //}; //_httpAccessor.HttpContext.Response.Cookies.Append("CartCookie", data, options); }
public async Task <IActionResult> Index(int?id) { //Null-coalescing operator // If id is not null set page to it, or if null start with one. int page = id ?? 1; // id is the page number coming in //Create a list of all VG in database for display purposes const int PageSize = 3; List <VideoGame> games = await VideoGameDb.GetGamesByPage(_context, page, PageSize); //Maximum page int totalPages = await VideoGameDb.GetTotalPages(_context, PageSize); ViewData["Pages"] = totalPages; ViewData["CurrentPage"] = page; return(View(games)); }
public async Task <IActionResult> Add(VideoGame game) { if (ModelState.IsValid) { // Add to Database await VideoGameDb.AddAsync(game, _context); return(RedirectToAction("Index")); } else { TempData["Error"] = true; } // Return view with model including error messages return(View(game)); }
// Add the game to a cookie public async Task <IActionResult> Add(int id) { VideoGame g = await VideoGameDb.GetGameById(id, _context); CartHelper.Add(_httpAccessor, g); /* * string data = JsonConvert.SerializeObject(g); * CookieOptions options = new CookieOptions() * { * Secure = true, * MaxAge = TimeSpan.FromDays(14) * }; * * _httpAccessor.HttpContext.Response.Cookies.Append("CartCookie", data, options); */ return(RedirectToAction("Index", "Library")); }
public async Task <IActionResult> Add(int id) { //Get the game with the corresponding id VideoGame g = await VideoGameDb.GetGameById(id, _context); //Convert game to a string CartHelper.Add(_httpAccessor, g); //Set up cookie //CookieOptions options = new CookieOptions() //{ // Secure = true, // MaxAge = TimeSpan.FromDays(365) //The cookie data will last up to a year //}; //_httpAccessor.HttpContext.Response.Cookies.Append("CartCookie", data, options); return(RedirectToAction("Index", "Library")); }
public async Task <IActionResult> Add(int id) { VideoGame g = await VideoGameDb.GetGameById(id, _context); CartHelper.Add(_httpAccessor, g); return(RedirectToAction("Index", "Library")); // get game with the associated id, add the game to a cookie, // redirect to catalog, // convert object to string using Json.NET //string data = JsonConvert.SerializeObject(g); //// set up cookie //CookieOptions options = new CookieOptions() //{ // Secure = true, // MaxAge = TimeSpan.FromDays(14) // two weeks //}; //_httpAccessor.HttpContext.Response.Cookies.Append("CartCookie", data, options); }