private async Task ReportMatchResult(DTO.MatchSeries.AdditionalMatchSeriesData payload) { using (var scope = this.provider.CreateScope()) { var alexandriaContext = scope.ServiceProvider.GetService <Alexandria.EF.Context.AlexandriaContext>(); var superSmashContext = scope.ServiceProvider.GetService <SuperSmashBrosContext>(); var matchSeriesExists = await alexandriaContext.MatchSeries.AnyAsync(ms => ms.Id == payload.MatchSeriesId); if (matchSeriesExists) { EF.Models.MatchReport matchReport = await superSmashContext.MatchReports.Include(mr => mr.FighterPicks).FirstOrDefaultAsync(mr => mr.MatchSeriesId == payload.MatchSeriesId); if (matchReport == null) { matchReport = new EF.Models.MatchReport(payload.MatchSeriesId); superSmashContext.MatchReports.Add(matchReport); } foreach (var fighterPick in payload.FighterPicks) { var fighterExists = await superSmashContext.Fighters.AnyAsync(f => f.Id == fighterPick.FighterId); var teamExists = await alexandriaContext.Teams.AnyAsync(t => t.Id == fighterPick.TeamId); if (fighterExists && teamExists) { var fighterPickModel = new EF.Models.FighterPick(fighterPick.TeamId, fighterPick.FighterId, fighterPick.MatchId); matchReport.FighterPicks.Add(fighterPickModel); } await superSmashContext.SaveChangesAsync(); } } } }
public async Task <ServiceResult> ReportMatchSeries(Guid matchSeriesId, MatchSeriesResultReportingRequest matchSeriesResult) { var result = new ServiceResult(); var existingMatches = matchSeriesResult.Results.Where(mr => mr.MatchId.HasValue); var reportingResult = await this.matchService.ReportMatchSeriesResult(matchSeriesId, existingMatches); if (!reportingResult.Success) { return(reportingResult); } var reportableMatches = existingMatches.Where(em => em.MapId.HasValue); foreach (var matchResult in reportableMatches) { var matchReport = new EF.Models.MatchReport(matchResult.MatchId.Value, matchResult.MapId.Value, matchResult.ReplayURL); this.heroesOfTheStormContext.MatchReports.Add(matchReport); } foreach (var mapBan in matchSeriesResult.MapBans) { var ban = new EF.Models.MapBan(mapBan.MapId, mapBan.TeamId, matchSeriesId); heroesOfTheStormContext.MapBans.Add(ban); } return(result); }