Exemplo n.º 1
0
        public async Task InsertUpdateMatch(object matchInfo, int phaseId, bool removeMatch)
        {
            var matchDTO = convertMatchInfo(matchInfo);

            using (var matchService = new MatchService())
                using (var competitorService = new CompetitorService(matchService.DbContext))
                    using (var competitionPhaseService = new CompetitionPhaseService(matchService.DbContext))
                    {
                        var settings = competitionPhaseService.GetCompetitionPhaseInfoSettings(phaseId) as GroupPhaseSettings;
                        // update of match
                        var matchSettings = removeMatch ? null : extractMatchInfo(matchDTO);
                        matchService.UpdateMatch(matchDTO.MatchId, matchSettings);

                        // update of all competitors
                        var competitors = matchService.DbContext.CompetitorPhaseInfoes.Where(x => x.IdCompetitionPhase == phaseId).ToList();
                        var matches     = matchService.GetMatches <TableTennisMatchInfo>(phaseId);

                        // update only match group
                        var groupIndex   = matchDTO.GroupIndex;
                        var groupMatches = matches.Where(x => settings.MatchIds[groupIndex].Contains(x.MatchId)).ToList();
                        var groupPlayers = competitors.Where(x => settings.CompetitorIds[groupIndex].Contains(x.IdCompetitor)).ToList();

                        var sorter = GetNewSorter();
                        sorter.LoadSortData(groupMatches);
                        var sortedData = sorter.SortCompetitors();
                        updateCompetitors(groupPlayers, sortedData);

                        await matchService.SaveChangesAsync();
                    }
        }
        public async Task <IHttpActionResult> UpdateCompetitors(int competitionId, [FromBody] List <CompetitorCreationInfoDTO> competitors)
        {
            using (var competitionPhaseService = new CompetitionPhaseService())
                using (var competitorService = new CompetitorService(competitionPhaseService.DbContext))
                {
                    // TODO: HACK
                    competitionPhaseService.DeleteCompetitionPhase(competitionId);
                    competitorService.UpdateCompetitors(competitionId, competitors);
                    await competitorService.DbContext.SaveChangesAsync();

                    return(Ok());
                }
        }
Exemplo n.º 3
0
        public List <CompetitionPhaseInfoDTO> GetCompetitonPhaseDTO(int competitionId)
        {
            using (var competitionPhaseService = new CompetitionPhaseService())
                using (var competitorService = new CompetitorService(competitionPhaseService.DbContext))
                {
                    var phases = competitionPhaseService.GetCompetitionPhaseInfos(competitionId);
                    if (phases?.Count() > 0)
                    {
                        var firstPhase   = phases.First();
                        var firstPhaseId = firstPhase.CompetitionPhaseId;
                        var matches      = competitionPhaseService.DbContext.Matches.Where(x => x.IdCompetitionPhase == firstPhaseId).ToList();
                        firstPhase.PhaseCompetitors = getPhaseCompetitorsDTO(competitorService.GetCompetitorPhaseInfos(firstPhase.CompetitionPhaseId), matches, firstPhase.Settings as GroupPhaseSettings);
                    }

                    return(phases);
                }
        }
        public async Task <IHttpActionResult> InsertCompetitionPhase(int competitionId, [FromBody] CompetitionCreationInfoDTO competitionSettings)
        {
            try
            {
                using (var competitionPhaseService = new CompetitionPhaseService())
                {
                    // TODO: HACK
                    competitionPhaseService.DeleteCompetitionPhase(competitionId);
                    var competitionPhaseId = await competitionPhaseService.CreateNewCompetitionPhase(competitionId, 1, competitionSettings);

                    return(Ok(competitionPhaseId));
                }
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }