public List <Tournament> ImportedTournaments() { var access = _accessService.GetList().LastOrDefault(a => a.DocumentType == nameof(Tournament)); var importedTournaments = new List <Tournament>(); foreach (var t in access.Documents) { importedTournaments.Add(_tournamentService.GetItem(t.Id)); } return(importedTournaments); }
public List <Match> ImportedMatches() { var access = _accessService.GetList().FirstOrDefault(a => a.DocumentType == nameof(Match)); var importedMatches = new List <Match>(); foreach (var t in access.Documents) { importedMatches.Add(_matchService.GetItem(t.Id)); } return(importedMatches); }
public List <Team> ImportedTeams(IDataSeedService <Tournament> tournamentService) { var access = _accessService.GetList().FirstOrDefault(a => a.DocumentType == nameof(Tournament)); var importedTeams = new List <Team>(); foreach (var t in access.Documents) { var importedtournament = tournamentService.GetItem(t.Id); importedTeams.AddRange(importedtournament.Teams); } return(importedTeams); }
public MatchViewModel(IDataSeedService <Match> matchService, string matchId) { _matchService = matchService ?? throw new ArgumentNullException($"matchService is null, cannot get match."); Match = _matchService.GetItem(matchId) ?? throw new ArgumentNullException($"Match Id is not exist"); }
public Match AddMatch(string hometeamid, string awayteamid, string oversOrTournamentId, string location, string primaryumpire, string secondaryumpire) { var hometeam = _teamService.GetItem(hometeamid); if (hometeam == null) { throw new NullReferenceException("Home team name is not added"); } var awayteam = _teamService.GetItem(awayteamid); if (awayteam == null) { throw new NullReferenceException("Away team name is not added"); } int overs; string tournamentId = string.Empty; if (_isTournament) { tournamentId = oversOrTournamentId; overs = _tournamentService.GetItem(tournamentId).TotalOvers; } else { overs = int.Parse(oversOrTournamentId); } var match = new Match { HomeTeam = new TeamInning(), AddDate = DateTime.Now, AwayTeam = new TeamInning(), Location = location, PrimaryUmpire = primaryumpire, SecondaryUmpire = secondaryumpire, TotalOvers = overs }; var matchId = _matchService.Create(match); var matchIdKey = new KeyValuePair <string, string>("matchId", matchId); var tournamentIdKey = new KeyValuePair <string, string>("tournamentId", tournamentId); // Creating team innings and player innings and update match var teamInningService = new DataSeedService <TeamInning>(_client); var playerInningService = new DataSeedService <PlayerInning>(_client); var hometeaminningId = teamInningService.Create(new TeamInning { TeamName = hometeam.Name, }, new KeyValuePair <string, string>[] { matchIdKey, tournamentIdKey, new KeyValuePair <string, string>("teamId", hometeam.Id) }); foreach (var homeplayername in hometeam.Players) { var homeplayerinningId = playerInningService.Create(new PlayerInning { PlayerName = homeplayername, }, new KeyValuePair <string, string>[] { matchIdKey, tournamentIdKey, new KeyValuePair <string, string>("teamId", hometeam.Id), new KeyValuePair <string, string>("playerId", $"{hometeam.Id}:{homeplayername}") }); } var awayteaminningId = teamInningService.Create(new TeamInning { TeamName = awayteam.Name, }, new KeyValuePair <string, string>[] { matchIdKey, tournamentIdKey, new KeyValuePair <string, string>("teamId", awayteam.Id) }); foreach (var awayplayername in awayteam.Players) { var awayplayerinningId = playerInningService.Create(new PlayerInning { PlayerName = awayplayername, }, new KeyValuePair <string, string>[] { matchIdKey, tournamentIdKey, new KeyValuePair <string, string>("teamId", awayteam.Id), new KeyValuePair <string, string>("playerId", $"{awayteam.Id}:{awayplayername}") }); } //Update Match var updatematch = _matchService.GetItem(matchId); updatematch.HomeTeam = teamInningService.GetItem(hometeaminningId); updatematch.AwayTeam = teamInningService.GetItem(awayteaminningId); _matchService.Update(matchId, updatematch); return(updatematch); }
public TeamViewModel(IDataSeedService <Team> teamService, string teamId) { _teamService = teamService ?? throw new ArgumentNullException($"TeamService is null, cannot get teams."); Team = _teamService.GetItem(teamId) ?? throw new ArgumentNullException($"Team Id is not exist"); }
public TournamentViewModel(IDataSeedService <Tournament> tournamentService, string tournamentId) { _tournamentService = tournamentService ?? throw new ArgumentNullException($"TournamentService is null, cannot get tournaments."); Tournament = _tournamentService.GetItem(tournamentId) ?? throw new ArgumentNullException($"Tournament Id is not exist"); }