Exemple #1
0
        private IEnumerable <string> ListOfYears()
        {
            // instantiate a repository
            VideoGameRepository videoGameRepository = new VideoGameRepository();

            // return the data context as an enumerable
            IEnumerable <VideoGame> videoGames;

            using (videoGameRepository)
            {
                videoGames = videoGameRepository.SelectAll() as IList <VideoGame>;
            }

            // get a distinct list of years
            var dates = videoGames.Select(v => v.ReleaseYear).Distinct().OrderBy(x => x);

            return(dates);
        }
Exemple #2
0
        public ActionResult Index(string sortOrder, int?page)
        {
            // instantiate a repository
            VideoGameRepository videoGameRepository = new VideoGameRepository();

            // create a distinct list of years for the years filter
            ViewBag.Years = ListOfYears();

            // return the data context as an enumerable
            IEnumerable <VideoGame> videoGames;

            using (videoGameRepository)
            {
                videoGames = videoGameRepository.SelectAll() as IList <VideoGame>;
            }

            // sort by name unless posted as a new sort
            // *Note* don't need .ToList() ?... videoGames = videoGames.ToList().OrderBy(v => v.ReleaseDate);
            switch (sortOrder)
            {
            case "ReleaseDate":
                videoGames = videoGames.OrderBy(v => v.ReleaseYear);
                break;

            default:
                videoGames = videoGames.OrderBy(v => v.Name);
                break;
            }

            // set parameters and paginate the video game list
            int pageSize   = 50;
            int pageNumber = (page ?? 1);

            videoGames = videoGames.ToPagedList(pageNumber, pageSize);

            return(View(videoGames));
        }
Exemple #3
0
        public ActionResult Index(string searchCriteria, string yearFilter, int?page)
        {
            // instantiate a repository
            VideoGameRepository videoGameRepository = new VideoGameRepository();

            // create a distinct list of years for the years filter
            ViewBag.Years = ListOfYears();

            // return the data context as an enumerable
            IEnumerable <VideoGame> videoGames;

            using (videoGameRepository)
            {
                videoGames = videoGameRepository.SelectAll() as IList <VideoGame>;
            }

            // if posted with a search on video game name
            if (searchCriteria != null)
            {
                videoGames = videoGames.Where(v => v.Name.ToUpper().Contains(searchCriteria.ToUpper()));
            }

            // if posted with a filter on release year
            if (yearFilter != "" || yearFilter == null)
            {
                videoGames = videoGames.Where(v => v.ReleaseYear == yearFilter);
            }

            // set parameters and paginate the video game list
            int pageSize   = 50;
            int pageNumber = (page ?? 1);

            videoGames = videoGames.ToPagedList(pageNumber, pageSize);

            return(View(videoGames));
        }