Beispiel #1
0
        public async Task <Result> InsertNewMatchesForSeason(IExceptionNotifier exceptionNotifier, IRootAggregateRepository <FootballTeam> rootAggregateRepositoryFootBallTeam, string seasonIdForFootballMatches, List <FootBallMatch> footBallMatches)
        {
            Result vtr = new Result(true);

            try
            {
                bool footballMatchesAreValid = footBallMatches?.Any() ?? false;
                bool seasonIdIsValid         = !String.IsNullOrWhiteSpace(seasonIdForFootballMatches);
                if (!footballMatchesAreValid || !seasonIdIsValid)
                {
                    List <string> invalidArguments = new List <string>();
                    if (!footballMatchesAreValid)
                    {
                        invalidArguments.Add(nameof(footBallMatches));
                    }

                    if (!seasonIdIsValid)
                    {
                        invalidArguments.Add(nameof(seasonIdForFootballMatches));
                    }

                    vtr.SetErrorInvalidArguments(invalidArguments.ToArray());
                }
                else
                {
                    if (SeasonIdForFootballMatches?.Equals(seasonIdForFootballMatches, StringComparison.OrdinalIgnoreCase) ?? false)
                    {
                        vtr.SetError($"Matches with season id {seasonIdForFootballMatches} have already been added");
                    }
                    else
                    {
                        SeasonIdForFootballMatches    = seasonIdForFootballMatches;
                        JSListOfFootBallMatch_Matches = footBallMatches.SerializeToJson();
                        LastUpdateOfSeasonMatches     = DateTime.UtcNow;
                        vtr = await rootAggregateRepositoryFootBallTeam.Update(this);
                    }
                }
            }
            catch (Exception ex)
            {
                await exceptionNotifier.Notify(ex, vtr);
            }
            return(vtr);
        }
Beispiel #2
0
        public async Task <Result> AddFullTimeLiveMatchStats(IExceptionNotifier exceptionNotifier, IRootAggregateRepository <FootballTeam> rootAggregateRepositoryFootballTeam, LiveMatchStats fullTimeLiveMatchStats)
        {
            Result vtr = new Result();

            try
            {
                if (fullTimeLiveMatchStats == null || String.IsNullOrWhiteSpace(fullTimeLiveMatchStats.MatchId))
                {
                    vtr.SetErrorInvalidArguments(nameof(fullTimeLiveMatchStats));
                }
                else
                {
                    if (fullTimeLiveMatchStats.MatchStatus != MatchStatus.FullTime)
                    {
                        vtr.SetError("Match is not over yet");
                    }
                    else
                    {
                        List <FootBallMatch> matches    = JSListOfFootBallMatch_Matches.DeserializeFromJson <List <FootBallMatch> >();
                        FootBallMatch        matchToSet = matches.FirstOrDefault(m => m.MatchId == fullTimeLiveMatchStats.MatchId);
                        if (matchToSet == null)
                        {
                            vtr.SetError($"Match with match id {fullTimeLiveMatchStats.MatchId} was not found");
                        }
                        else
                        {
                            matchToSet.FullTimeMatchStats = fullTimeLiveMatchStats;
                            JSListOfFootBallMatch_Matches = matches.SerializeToJson();
                            vtr = await rootAggregateRepositoryFootballTeam.Update(this);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await exceptionNotifier.Notify(ex, vtr);
            }
            return(vtr);
        }