Ejemplo n.º 1
0
 public void TestInsert()
 {
     var t = new Team {Name = "Test"};
     var repo = new MongoRepository<Team>(_db);
     repo.Save(t);
     Assert.NotNull(t.Id);
 }
Ejemplo n.º 2
0
 public void AddTeam(Competition competition, Team team)
 {
     if (competition.IsLocked)
     {
         throw new CannotAddTeamInLockedCompetition();
     }
     competition.AddTeam(team);
     _competitionRepo.Save(competition);
 }
Ejemplo n.º 3
0
        public void UpdatePlayedGame(Team team, bool isWin)
        {
            if(isWin)
             {
                 team.WinInARow++;
             }
             team.GamePlayed++;

             Save(team);
        }
Ejemplo n.º 4
0
        public ActionResult AddTeamInCompetitionDebug(string competitionId, int nbTeam)
        {
            var competition = CompetitionService.Find(competitionId);

            for (int i = 0; i < nbTeam; i++)
            {
                var team = new Team(string.Format("{0}-Team{1}", competition.Name, i), false, i + 1);
                _teamService.Save(team);
                CompetitionService.AddTeam(competition, team);
            }

            return RedirectToAction("Edit", "Competition", new { id = competitionId });
        }
Ejemplo n.º 5
0
        public void TestGetById()
        {
            var repo = new MongoRepository<Team>(_db);
            var team = new Team()
            {
                Name = "Tom"
            };
            repo.Save(team);
            var id = team.Id;

            var teamRefresh = repo.Find(id);

            Assert.AreEqual(teamRefresh.Name, "Tom");
        }
Ejemplo n.º 6
0
        public Result CreateResult(Node rootNode, Team teamWin)
        {
            var nodeOfTeamWin = SearchNodeOfTeam(teamWin, rootNode);

            if (nodeOfTeamWin.ParentNode == null)
            {
                throw new ResultImpossibleException();
            }

            var nodeOfTeamLoose = nodeOfTeamWin.ParentNode.BottomNode == nodeOfTeamWin ? nodeOfTeamWin.ParentNode.TopNode : nodeOfTeamWin.ParentNode.BottomNode;

            var result = new Result { TeamWin = teamWin, TeamLoose = nodeOfTeamLoose.Team, DepthOfTheGame = nodeOfTeamWin.DepthOfTheTree};

            _teamService.UpdatePlayedGame(result);

            _resultRepo.Save(result);

            return result;
        }
Ejemplo n.º 7
0
        public void AddResult(Competition competition, Team team)
        {
            var rootNode = _nodeService.GetTree(competition);
            var result = _nodeService.CreateResult(rootNode, team);

            if (!competition.IsCryingCompetion)
            {
                if (team.CanSendToCryingCompetetion)
                {
                    var cryingCompetition = GetCryingCompetition(competition);

                    if (result.TeamLoose != null)
                    {
                        AddTeamInCryingCompetition(cryingCompetition, result.TeamLoose);
                    }

                    Save(cryingCompetition);
                }
            }

            competition.Results.Add(result);
            _priceService.AttributeGain(competition, result);
            Save(competition);
        }
Ejemplo n.º 8
0
 public void AddTeam(Team team)
 {
     InitialTeams.Add(team);
 }
Ejemplo n.º 9
0
 public void CreateTeamInCompetion(Team team, Competition competition)
 {
     competition.AddTeam(team);
     Save(competition);
 }
Ejemplo n.º 10
0
 private void PopulateCryingCompetition(Competition competition)
 {
     if (competition.IsCryingCompetion && !competition.InitialTeams.Any())
     {
         var mainCompetition = GetMainCompetition(competition);
         competition.NbTeamMainCompetition = mainCompetition.NumberOfTeam;
         int nbTeamToAdd = competition.NumberOfTeam;
         for (int i = 0; i < nbTeamToAdd; i++)
         {
             var team = new Team("A remplacer", true, 0);
             competition.InitialTeams.Add(team);
             _competitionRepo.Save(competition);
         }
     }
 }
Ejemplo n.º 11
0
 void AddTeamInCryingCompetition(Competition competition, Team team)
 {
     var teamToReplace = competition.InitialTeams.FirstOrDefault(x => x.IsTeamToReplace);
     if (teamToReplace == null)
     {
         throw new Exception("pas possible normalement, learn to code noob");
     }
     competition.InitialTeams.Remove(teamToReplace);
     competition.AddTeam(team);
     team.WinInARow = 0;
     _teamRepo.Save(team);
     Save(competition);
 }
Ejemplo n.º 12
0
 public bool IsTeamIsEliminated(Competition competition, Team team)
 {
     return competition.Results.Any(x => x.TeamLoose == team);
 }
Ejemplo n.º 13
0
 public void Save(Team team)
 {
     _teamRepo.Save(team);
 }
Ejemplo n.º 14
0
        private Node SearchNodeOfTeam(Team team, Node rootNode)
        {
            if (rootNode.Team != null && rootNode.Team.Id == team.Id)
            {
                return rootNode;
            }

            Node tmpNode;

            if (rootNode.BottomNode != null)
            {
                tmpNode = SearchNodeOfTeam(team, rootNode.BottomNode);
                if (tmpNode != null) return tmpNode;
            }

            if (rootNode.TopNode != null)
            {
                tmpNode = SearchNodeOfTeam(team, rootNode.TopNode);
                if (tmpNode != null) return tmpNode;
            }

            return null;
        }
Ejemplo n.º 15
0
        public ActionResult PartialCreate(TeamDto teamDto)
        {
            try
            {
                var team = new Team(teamDto.Nom, false, teamDto.Number);
                _teamService.Save(team);
                if (!string.IsNullOrEmpty(teamDto.CompetitionId))
                {
                    var competition = CompetitionService.Find(teamDto.CompetitionId);
                    CompetitionService.CreateTeamInCompetion(team, competition);

                    return RedirectToAction("AddTeamInCompetitionPartial", "Team", new { competitionId = teamDto.CompetitionId });
                }
                throw new Exception();
            }
            catch
            {
                return View();
            }
        }