public void AddChosenTeam(string gameId, Team chosenTeam) { var game = GetGame(gameId); if (game == null) { throw new NotFoundException($"Game with ID '{gameId}' not found"); } game.CurrentTeam = chosenTeam; using (var repository = new RepositoryFactory().CreateUnitOfWorkRepository()) { repository.RegisterUpdate(game); repository.Save(); } }
public void PlayMatchDay(string seasonId, DateTime matchDay) { // First check if the given matchDay is the "next" match day DateTime nextMatchDay = GetNextMatchDay(seasonId); if (!nextMatchDay.Equals(matchDay)) { throw new ConflictException("These matches can't be played now"); } var matchesToPlay = GetBySeasonAndDate(seasonId, matchDay).ToList(); if (!matchesToPlay.Any()) { throw new NotFoundException("There are no matches on this day"); } foreach (var match in matchesToPlay) { Play(match); } using (var repository = new RepositoryFactory().CreateUnitOfWorkRepository()) { var seasonManager = new SeasonManager(Game); var postMatchManager = new PostMatchManager(repository, seasonManager); postMatchManager.DoSomething(matchesToPlay); // Save the result. repository.RegisterUpdate(matchesToPlay); repository.Save(); } }
//public void Delete(Team team) //{ // using (var teamRepository = new RepositoryFactory().GetTeamRepository()) // { // teamRepository.Delete(team); // } //} public void UpdateRating(Team team, IEnumerable<Player> squad) { decimal teamRating = TeamRater.GetRating(squad); team.Rating = teamRating; using (var repository = new RepositoryFactory().CreateUnitOfWorkRepository()) { repository.RegisterUpdate(team); repository.Save(); } }
public Game CreateGameForUser(string userId) { Game game; using (var gameRepository = new RepositoryFactory().CreateGameRepository()) { game = gameRepository.Find(x => x.UserId == null).FirstOrDefault(); } if (game != null) { game.UserId = userId; using (var repository = new RepositoryFactory().CreateUnitOfWorkRepository()) { repository.RegisterUpdate(game); repository.Save(); } } return game; }
public void SubstitutePlayers(Player player1, Player player2) { // Update the team order of both players. int oldPlayer1TeamOrder = player1.TeamOrder; int oldPlayer2TeamOrder = player2.TeamOrder; player1.TeamOrder = oldPlayer2TeamOrder; player2.TeamOrder = oldPlayer1TeamOrder; using (var repository = new RepositoryFactory().CreateUnitOfWorkRepository()) { repository.RegisterUpdate(player1); repository.RegisterUpdate(player2); repository.Save(); } var team = player1.Team; new TeamService(Game).UpdateRating(team); }