public void TestInsert() { var t = new Team {Name = "Test"}; var repo = new MongoRepository<Team>(_db); repo.Save(t); Assert.NotNull(t.Id); }
public void AddTeam(Competition competition, Team team) { if (competition.IsLocked) { throw new CannotAddTeamInLockedCompetition(); } competition.AddTeam(team); _competitionRepo.Save(competition); }
public void UpdatePlayedGame(Team team, bool isWin) { if(isWin) { team.WinInARow++; } team.GamePlayed++; Save(team); }
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 }); }
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"); }
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; }
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); }
public void AddTeam(Team team) { InitialTeams.Add(team); }
public void CreateTeamInCompetion(Team team, Competition competition) { competition.AddTeam(team); Save(competition); }
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); } } }
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); }
public bool IsTeamIsEliminated(Competition competition, Team team) { return competition.Results.Any(x => x.TeamLoose == team); }
public void Save(Team team) { _teamRepo.Save(team); }
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; }
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(); } }