Esempio n. 1
0
        public ActionResult Index(string searchBy, string classFilter)
        {
            ChampionRepository championRepository = new ChampionRepository();

            ViewBag.Classes = ListOfClasses();

            IEnumerable <Champion> champions;

            using (championRepository)
            {
                champions = championRepository.GetAllChampions() as IList <Champion>;
            }

            if (searchBy != null)
            {
                champions = champions.Where(champ => champ.Name.ToUpper().Contains(searchBy.ToUpper()));
            }

            if (classFilter != "" || classFilter == null)
            {
                champions = champions.Where(champ => champ.Class == classFilter);
            }

            return(View(champions));
        }
Esempio n. 2
0
        private IEnumerable <string> ListOfClasses()
        {
            ChampionRepository championRepository = new ChampionRepository();

            IEnumerable <Champion> champions;

            using (championRepository)
            {
                champions = championRepository.GetAllChampions() as IList <Champion>;
            }
            var classes = champions.Select(champ => champ.Class).Distinct().OrderBy(c => c);

            return(classes);
        }
        public void RecalculateForSingleGame()
        {
            using (var dataContext = GetInstanceFromRootContainer <IDataContext>())
            {
                IChampionRepository championRepository = new ChampionRepository(dataContext);

                IChampionRecalculator championRecalculator = new ChampionRecalculator(dataContext, championRepository);
                ApplicationUser       user = new ApplicationUser
                {
                    Id = "80629c07-b8df-4deb-a9e3-5b503ce7d7df",
                    CurrentGamingGroupId = 1
                };
                championRecalculator.RecalculateChampion(2005, user, dataContext);
            }
        }
Esempio n. 4
0
        private Champion GetChampionById(int id)
        {
            Champion champ = new Champion();


            ChampionRepository championRepository = new ChampionRepository();

            IEnumerable <Champion> champions;

            using (championRepository)
            {
                champions = championRepository.GetAllChampions() as IList <Champion>;
            }

            champ = champions.Where(c => c.Id == id).FirstOrDefault();

            return(champ);
        }
Esempio n. 5
0
        public ActionResult Delete(Champion champ)
        {
            try
            {
                ChampionRepository championRepository = new ChampionRepository();

                using (championRepository)
                {
                    championRepository.Delete(champ.Id);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 6
0
        public void RecalculateForSingleGame()
        {
            using (NemeStatsDbContext dbContext = new NemeStatsDbContext())
            {
                SecuredEntityValidatorFactory factory = new SecuredEntityValidatorFactory();

                using (NemeStatsDataContext dataContext = new NemeStatsDataContext(dbContext, factory))
                {
                    IChampionRepository championRepository = new ChampionRepository(dataContext);

                    IChampionRecalculator championRecalculator = new ChampionRecalculator(dataContext, championRepository);
                    ApplicationUser       user = new ApplicationUser
                    {
                        Id = "80629c07-b8df-4deb-a9e3-5b503ce7d7df",
                        CurrentGamingGroupId = 1
                    };
                    championRecalculator.RecalculateChampion(2005, user);
                }
            }
        }
Esempio n. 7
0
        public ActionResult Edit(Champion champ)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View());
                }

                ChampionRepository championRepository = new ChampionRepository();

                using (championRepository)
                {
                    championRepository.Update(champ);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 8
0
        public ActionResult Index(string sortOrder)
        {
            ChampionRepository championRepository = new ChampionRepository();

            ViewBag.Classes = ListOfClasses();

            IEnumerable <Champion> champions;

            using (championRepository)
            {
                champions = championRepository.GetAllChampions() as IList <Champion>;
            }

            switch (sortOrder)
            {
            case "Name":
                champions = champions.OrderBy(champion => champion.Name);
                break;

            case "Class":
                champions = champions.OrderBy(champion => champion.Class);
                break;

            case "Base Health":
                champions = champions.OrderBy(champion => champion.BaseHealth);
                break;

            case "Base Mana":
                champions = champions.OrderBy(champion => champion.BaseMana);
                break;

            default:
                break;
            }

            return(View(champions));
        }
Esempio n. 9
0
        private void CreatePlayedGames(NemeStatsDataContext dataContext)
        {
            IPlayerRepository                        playerRepository                        = new EntityFrameworkPlayerRepository(dataContext);
            INemesisRecalculator                     nemesisRecalculator                     = new NemesisRecalculator(dataContext, playerRepository);
            IChampionRepository                      championRepository                      = new ChampionRepository(dataContext);
            IChampionRecalculator                    championRecalculator                    = new ChampionRecalculator(dataContext, championRepository);
            ISecuredEntityValidator <Player>         securedEntityValidatorForPlayers        = new SecuredEntityValidator <Player>();
            ISecuredEntityValidator <GameDefinition> securedEntityValidatorForGameDefinition = new SecuredEntityValidator <GameDefinition>();
            IPlayedGameCreator                       playedGameCreator                       = new PlayedGameCreator(
                dataContext,
                playedGameTracker,
                nemesisRecalculator,
                championRecalculator,
                securedEntityValidatorForPlayers,
                securedEntityValidatorForGameDefinition);

            List <Player> players = new List <Player>()
            {
                testPlayer1, testPlayer2
            };
            List <int> playerRanks = new List <int>()
            {
                1, 1
            };
            PlayedGame playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameCreator);

            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer1, testPlayer2, testPlayer3
            };
            playerRanks = new List <int>()
            {
                1, 2, 3
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer1, testPlayer3, testPlayer2
            };
            playerRanks = new List <int>()
            {
                1, 2, 3
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer3, testPlayer1
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            //make player4 beat player 1 three times
            players = new List <Player>()
            {
                testPlayer4, testPlayer1, testPlayer2, testPlayer3
            };
            playerRanks = new List <int>()
            {
                1, 2, 3, 4
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer4, testPlayer1
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer4, testPlayer1
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            //--make the inactive player5 beat player1 3 times
            players = new List <Player>()
            {
                testPlayer5, testPlayer1
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer5, testPlayer1
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer5, testPlayer1
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            //make player 2 be the only one who beat player 5
            players = new List <Player>()
            {
                testPlayer2, testPlayer5
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            //--create games that have a different GamingGroupId and testPlayer7 being the champion
            players = new List <Player>()
            {
                testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int>()
            {
                1
            };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer7WithOtherGamingGroupId, testPlayer8WithOtherGamingGroupId
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer7WithOtherGamingGroupId, testPlayer8WithOtherGamingGroupId
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer7WithOtherGamingGroupId, testPlayer8WithOtherGamingGroupId
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer7WithOtherGamingGroupId, testPlayer8WithOtherGamingGroupId
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer8WithOtherGamingGroupId, testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);

            players = new List <Player>()
            {
                testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int>()
            {
                1, 2
            };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameCreator);
            testPlayedGames.Add(playedGame);
        }
Esempio n. 10
0
        private void CreatePlayedGames(NemeStatsDataContext dataContext)
        {
            var playerRepository          = new EntityFrameworkPlayerRepository(dataContext);
            var nemesisRecalculator       = new NemesisRecalculator(dataContext, playerRepository);
            var championRepository        = new ChampionRepository(dataContext);
            var championRecalculator      = new ChampionRecalculator(dataContext, championRepository);
            var securedEntityValidator    = new SecuredEntityValidator(dataContext);
            var weightBonusCalculator     = new WeightBonusCalculator(new WeightTierCalculator());
            var pointsCalculator          = new PointsCalculator(weightBonusCalculator, new GameDurationBonusCalculator());
            var linkedPlayedGameValidator = new LinkedPlayedGameValidator(dataContext);
            var applicationLinker         = new ApplicationLinker(dataContext);

            IPlayedGameSaver playedGameSaver = new PlayedGameSaver(
                dataContext,
                playedGameTracker,
                nemesisRecalculator,
                championRecalculator,
                securedEntityValidator,
                pointsCalculator,
                new FakeEventBus(),
                linkedPlayedGameValidator,
                applicationLinker);

            List <Player> players = new List <Player> {
                testPlayer1, testPlayer2
            };
            List <int> playerRanks = new List <int> {
                1, 1
            };
            PlayedGame playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);

            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer1, testPlayer2, testPlayer3
            };
            playerRanks = new List <int> {
                1, 2, 3
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer1, testPlayer3, testPlayer2
            };
            playerRanks = new List <int> {
                1, 2, 3
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer3, testPlayer1
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            //make player4 beat player 1 three times
            players = new List <Player> {
                testPlayer4, testPlayer1, testPlayer2, testPlayer3
            };
            playerRanks = new List <int> {
                1, 2, 3, 4
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer4, testPlayer1
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer4, testPlayer1
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            //--make the inactive player5 beat player1 3 times
            players = new List <Player> {
                testPlayer5, testPlayer1
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer5, testPlayer1
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer5, testPlayer1
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            //make player 2 be the only one who beat player 5
            players = new List <Player> {
                testPlayer2, testPlayer5
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            //--create games that have a different GamingGroupId and testPlayer7 being the champion
            players = new List <Player> {
                testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int> {
                1
            };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer7WithOtherGamingGroupId, testPlayer8WithOtherGamingGroupId
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer7WithOtherGamingGroupId, testPlayer8WithOtherGamingGroupId
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer7WithOtherGamingGroupId, testPlayer8WithOtherGamingGroupId
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer7WithOtherGamingGroupId, testPlayer8WithOtherGamingGroupId
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer8WithOtherGamingGroupId, testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List <Player> {
                testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId
            };
            playerRanks = new List <int> {
                1, 2
            };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);
        }