private void updateTableCompetitionPhaseSettings(CompetitionPhase competitionPhase, CompetitionAdvancedOptionsDTO advancedOptions, Dictionary <int, List <Match> > matches, JArray competitorAllocations, Dictionary <int, Competitor> competitorLookup) { var competitionSettings = new GroupPhaseSettings(); if (!string.IsNullOrEmpty(competitionPhase.Settings)) { competitionSettings.PopulateObject(competitionPhase.Settings); } Dictionary <int, List <int> > matchIds = new Dictionary <int, List <int> >(); foreach (var groupMathces in matches) { matchIds.Add(groupMathces.Key, new List <int>()); matchIds[groupMathces.Key].AddRange(groupMathces.Value.Select(x => x.Id)); } competitionSettings.MatchIds = matchIds; competitionSettings.CompetitorIds = getCompetitorsGroupedByGroup(competitorAllocations, competitorLookup); competitionSettings.MatchInfoType = advancedOptions.MatchInfoType; competitionSettings.CompetitorPhaseInfoType = advancedOptions.CompetititorInfoType; competitionPhase.Settings = competitionSettings.SerializeObject(); }
public List <TableTennisTournamentMatchesVM> GenerateMatchesViewModel(List <Match> matches, GroupPhaseSettings groupPhaseSettings) { List <TableTennisTournamentMatchesVM> matchesVM = new List <TableTennisTournamentMatchesVM>(); foreach (var groupId in groupPhaseSettings.MatchIds.Keys) { foreach (var matchId in groupPhaseSettings.MatchIds[groupId]) { var match = matches.First(x => x.Id == matchId); var matchInfo = GetNewMatchInfo(); matchInfo.PopulateObject(match.MatchInfo); var matchVM = new TableTennisTournamentMatchesVM() { MatchId = match.Id, CompetitorId1 = match.IdCompetitor1, CompetitorId2 = match.IdCompetitor2, Leg = match.Leg, Sets1 = matchInfo.Sets1, Sets2 = matchInfo.Sets2, Result = matchInfo.Result, GroupIndex = groupId }; if (matchVM.Sets1 == null) { matchVM.Sets1 = new List <string>() { null, null, null, null, null, }; } if (matchVM.Sets2 == null) { matchVM.Sets2 = new List <string>() { null, null, null, null, null, }; } matchesVM.Add(matchVM); } } return(matchesVM); }
private PhaseCompetitorsDTO getPhaseCompetitorsDTO(List <PhaseCompetitorInfos> phaseCompetitorInfos, List <Match> matches, GroupPhaseSettings groupPhaseSettings) { PhaseCompetitorsDTO phaseCompetitorsDTO = new PhaseCompetitorsDTO(); phaseCompetitorsDTO.Columns = GetPlayerViewModelColumns(); var matchesVM = GenerateMatchesViewModel(matches, groupPhaseSettings); var playersVM = GeneratePlayersViewModel(phaseCompetitorInfos); phaseCompetitorsDTO.Competitors = playersVM.ToList <object>(); phaseCompetitorsDTO.Matches = matchesVM.ToList <object>(); return(phaseCompetitorsDTO); }