Beispiel #1
0
        public bool UpdateTeam()
        {
            var updated = _teamService.Update(Team.Id, Team);

            return(updated);
        }
        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);
        }
Beispiel #3
0
        public bool UpdateTournament()
        {
            var updated = _tournamentService.Update(Tournament.Id, Tournament);

            return(updated);
        }