public async Task <IActionResult> Update(int id)
        {
            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> 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)
            {
                //Add to database
                await VideoGameDB.AddAsync(game, _context);

                return(RedirectToAction("Index"));
            }
            //Return view with model including error messages
            return(View(game));
        }
Пример #5
0
        [HttpPost] //After they fill out the form and submit it
        public async Task <IActionResult> Update(VideoGame g)
        {
            if (ModelState.IsValid)
            {
                await VideoGameDB.UpdateGame(g, context);

                return(RedirectToAction("Index")); //Sends the user back to the video game index page
            }

            //If there are any errors, show the user the form again
            return(View(g));
        }
Пример #6
0
        [HttpGet] //ID is the page number coming in
        public async Task <IActionResult> Index(int?ID)
        {
            //Set to ID. If ID is null, set to 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;
            return(View(games));
        }
        [HttpGet] //id is the page number coming in
        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));
        }
Пример #8
0
        public async Task <IActionResult> Add(VideoGame game)
        {
            if (ModelState.IsValid)
            {
                // Add to Database (await must be called before you call an async method)
                await VideoGameDB.AddAsync(game, context);

                return(RedirectToAction("Index"));
            }
            ;

            // So that all of the errors that you encounter are sent with the view
            return(View(game));
        }
        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);
        }
Пример #10
0
        public async Task <IActionResult> Add(int ID)
        {
            //Get the game with the corresponding ID
            VideoGame g = await VideoGameDB.GetGameByID(ID, _context);

            //Convert game to string
            string data = JsonConvert.SerializeObject(g);

            CartHelper.Add(_httpAccessor, g);

            return(RedirectToAction("Index", "VideoGame"));
            //Set up cookie
            //CookieOptions options = new CookieOptions()
            //{
            //    Secure = true,
            //    MaxAge = TimeSpan.FromDays(2 * DaysInWeek)
            //};

            //THIS IS HOW YOU CREATE A COOKIE
            //_httpAccessor.HttpContext.Response.Cookies.Append("CartCookie", data, options);
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            await VideoGameDB.DeleteById(id, _context);

            return(RedirectToAction("Index"));
        }
Пример #12
0
        public async Task <IActionResult> Delete(int ID)
        {
            VideoGame game = await VideoGameDB.GetGameByID(ID, context);

            return(View(game));
        }