コード例 #1
0
        public async Task <IActionResult> Update(int id)
        {
            VideoGame game =
                await VideoGameDb.GetGameById(id, _context);

            return(View(game));
        }
コード例 #2
0
        public async Task <IActionResult> Index()
        {
            List <VideoGame> allGames =
                await VideoGameDb.GetAllGames(_context);

            return(View(allGames));
        }
コード例 #3
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            await VideoGameDb.DeleteById(id, _context);

            // Direct back to the index
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
 public async Task <IActionResult> Search(SearchCriteria criteria)
 {
     if (ValidSearch(criteria))
     {
         criteria.GameResults = await VideoGameDb.Search(_context, criteria);
     }
     return(View(criteria));
 }
コード例 #6
0
 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));
 }
コード例 #7
0
        public async Task <IActionResult> Update(VideoGame g)
        {
            if (ModelState.IsValid)
            {
                await VideoGameDb.UpdateGame(g, _context);

                return(RedirectToAction("Index"));
            }

            return(View(g));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        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));
        }
コード例 #13
0
        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));
        }
コード例 #14
0
        [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));
        }
コード例 #15
0
        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));
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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));
        }
コード例 #18
0
        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));
        }
コード例 #19
0
        // 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"));
        }
コード例 #20
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 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"));
        }
コード例 #21
0
        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);
        }