Exemplo n.º 1
0
        public async Task <ServiceResult <Guid> > CreateAndReportMatchResult(DTO.MatchSeries.MatchResultReport report,
                                                                             Guid matchSeriesId, int order)
        {
            var result      = new ServiceResult <Guid>();
            var matchSeries = await this.alexandriaContext.MatchSeries
                              .Include(ms => ms.MatchParticipants)
                              .ThenInclude(mp => mp.Team)
                              .FirstOrDefaultAsync(ms => ms.Id == matchSeriesId);

            if (matchSeries == null)
            {
                result.Error = Shared.ErrorKey.MatchSeries.NotFound;
                return(result);
            }


            var match = new Match(matchSeriesId);

            match.MatchSeries = matchSeries;
            match.MatchOrder  = order;
            this.alexandriaContext.Matches.Add(match);
            this.DangerouslyReportMatch(match, report);
            result.Succeed(match.Id);
            return(result);
        }
Exemplo n.º 2
0
        private void DangerouslyReportMatch(EF.Models.Match match, DTO.MatchSeries.MatchResultReport matchResult)
        {
            match.State        = Shared.Enums.MatchState.Complete;
            match.OutcomeState = matchResult.Outcome;

            foreach (var teamResult in matchResult.Results)
            {
                var participant = match.MatchSeries.GetParticipant(teamResult.TeamId);
                if (participant == null)
                {
                    throw new NoNullAllowedException("Participant can't be null");
                }
                var matchParticipantResult = new MatchParticipantResult(match.Id, participant.Id, teamResult.Result);
                match.Results.Add(matchParticipantResult);
            }

            //this.alexandriaContext.Matches.Update(match);
        }
Exemplo n.º 3
0
        public async Task <ServiceResult> ReportMatchResult(DTO.MatchSeries.MatchResultReport matchResult)
        {
            var result = new ServiceResult();

            if (!matchResult.MatchId.HasValue)
            {
                result.Error = Shared.ErrorKey.Match.NotFound;
                return(result);
            }

            var match = await this.alexandriaContext.Matches
                        .Include(m => m.Results)
                        .Include(m => m.MatchSeries)
                        .ThenInclude(ms => ms.MatchParticipants)
                        .ThenInclude(mp => mp.Team)
                        .FirstOrDefaultAsync(m => m.Id.Equals(matchResult.MatchId.Value));

            if (match == null)
            {
                result.Error = Shared.ErrorKey.Match.NotFound;
                return(result);
            }

            if (!match.State.Equals(Shared.Enums.MatchState.Pending))
            {
                result.Error = Shared.ErrorKey.Match.AlreadyReported;
                return(result);
            }

            var allTeamsParticipating = match.MatchSeries.MatchParticipants.Select(mp => mp.TeamId).All(tId => match.MatchSeries.IsParticipant(tId) == true);

            if (!allTeamsParticipating)
            {
                result.Error = Shared.ErrorKey.Match.InvalidParticipant;
                return(result);
            }

            this.DangerouslyReportMatch(match, matchResult);
            result.Succeed();
            return(result);
        }