Example #1
0
        static void Main(string[] args)
        {
            RentalContext       ctx         = new RentalContext();
            RentRepository      rentRepo    = new RentRepository(ctx);
            VideoGameRepository gameRepo    = new VideoGameRepository(ctx);
            PersonRepository    personRepo  = new PersonRepository(ctx);
            RentLogic           rentLogic   = new RentLogic(rentRepo);
            VideoGameLogic      gameLogic   = new VideoGameLogic(gameRepo);
            PersonLogic         personLogic = new PersonLogic(personRepo);

            Console.WriteLine(">List all rents");
            rentLogic.GetAllRentals().ToList().ForEach(x => Console.WriteLine(x.AllData));

            Console.WriteLine("\n\n##################################################\n");

            Console.WriteLine("\n\n>List all games");
            gameLogic.GetAllGames().ToList().ForEach(x => Console.WriteLine(x.AllData));

            Console.WriteLine("\n\n##################################################\n");

            Console.WriteLine("\n\n>List all people");
            personLogic.GetAllPeople().ToList().ForEach(x => Console.WriteLine(x.AllData));

            //##################################################


            Console.WriteLine(rentLogic.MostFine());
            Console.WriteLine(rentLogic.MostRentedGame());
            Console.WriteLine(rentLogic.MostRentsByPerson());
        }
Example #2
0
        public ActionResult Update(VideoGame videoGame)
        {
            var repo = new VideoGameRepository(Properties.Settings.Default.ConStr);

            repo.UpdateGame(videoGame);
            return(Json(videoGame));
        }
Example #3
0
        public ActionResult Delete(int id)
        {
            VideoGameRepository videoGameRepository = new VideoGameRepository();
            VideoGame           videoGame           = new VideoGame();

            using (videoGameRepository)
            {
                videoGame = videoGameRepository.SelectOne(id);
            }
            return(View(videoGame));
        }
        public void Setup()
        {
            RentalContext       ctx        = new RentalContext();
            RentRepository      rentRepo   = new RentRepository(ctx);
            VideoGameRepository gameRepo   = new VideoGameRepository(ctx);
            PersonRepository    personRepo = new PersonRepository(ctx);

            rentLogic   = new RentLogic(rentRepo);
            gameLogic   = new VideoGameLogic(gameRepo);
            personLogic = new PersonLogic(personRepo);
        }
Example #5
0
        // GET: VideoGame/Details/5
        public ActionResult Details(int id)
        {
            // instantiate a repository
            VideoGameRepository videoGameRepository = new VideoGameRepository();
            VideoGame           videoGame           = new VideoGame();

            // get a videoGame that has the matching id
            using (videoGameRepository)
            {
                videoGame = videoGameRepository.SelectOne(id);
            }

            return(View(videoGame));
        }
Example #6
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);
        }
Example #7
0
        public ActionResult Delete(int id, VideoGame videoGame)
        {
            try
            {
                VideoGameRepository videoGameRepository = new VideoGameRepository();

                using (videoGameRepository)
                {
                    videoGameRepository.Delete(id);
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                // TODO: add view for error message
                return(View("Error"));
            }
        }
Example #8
0
        public void update_video_game()
        {
            var       newName = "Unit Test";
            VideoGame videoGame;

            VideoGamesController vgc  = new VideoGamesController();
            VideoGameRepository  repo = new VideoGameRepository();

            videoGame = repo.GetVideoGameByID(1);

            //Update Name
            videoGame.Name = newName;

            //save
            vgc.PostVideoGame(videoGame);

            //requery from DB
            videoGame = repo.GetVideoGameByID(1);

            //check
            Assert.AreEqual(videoGame.Name, newName);
        }
Example #9
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));
        }
Example #10
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));
        }
Example #11
0
        public void Delete(int gameId)
        {
            var repo = new VideoGameRepository(Properties.Settings.Default.ConStr);

            repo.DeleteGame(gameId);
        }
Example #12
0
        public ActionResult Index()
        {
            var repo = new VideoGameRepository(Properties.Settings.Default.ConStr);

            return(View(repo.GetAll()));
        }
Example #13
0
 public VideoGameController()
 {
     _videoGameRepository = new VideoGameRepository();
 }
Example #14
0
        public VideoGameService()
        {
            var videoClubDi = new VideoClubDi(VideoClubContext.GetVideoClubContext());

            _videoGameRepository = new VideoGameRepository(videoClubDi);
        }