예제 #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();
                    }
        }
예제 #2
0
        public DisplayResults(Settings settings, CourseService courseService, CompetitorService competitorService)
        {
            _settings          = settings;
            _courseService     = courseService;
            _competitorService = competitorService;

            CalculateDataPerColumn();

            CalculateDataInTables();

            BuildDisplayTable();
        }
예제 #3
0
 public DisplayResultsHtml(Settings settings,
                           List <DisplayTable> listDisplayTable,
                           CompetitionService competitionService,
                           CourseService courseService,
                           CompetitorService competitorService)
 {
     _settings           = settings;
     _listDisplayTable   = listDisplayTable;
     _competitionService = competitionService;
     competition         = competitionService.GetFirst();
     _courseService      = courseService;
     _competitorService  = competitorService;
 }
        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());
                }
        }
 public async Task <IHttpActionResult> GetCompetitors(int competitionId)
 {
     using (var competitorService = new CompetitorService())
     {
         var competitorColumns = ColumnDefinitionFactory.ExtractColumnDefinitions(typeof(CompetitionInfo));
         var competitors       = competitorService.GetCompetitors(competitionId);
         return(Ok(new CompetitiorInfoDTO()
         {
             Columns = competitorColumns,
             Competitors = competitors
         }));
     }
 }
예제 #6
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);
                }
        }
예제 #7
0
        public CompetitorServiceTests()
        {
            _mockCalculator = new Mock <IScoringCalculator>();
            _mockCalculator.Setup(c => c.CalculateResults(It.IsAny <Series>())).Returns(new SeriesResults());
            _mockScoringCalculatorFactory = new Mock <IScoringCalculatorFactory>();
            _mockScoringCalculatorFactory.Setup(f => f.CreateScoringCalculatorAsync(It.IsAny <SailScores.Core.Model.ScoringSystem>()))
            .ReturnsAsync(_mockCalculator.Object);

            _context = Utilities.InMemoryContextBuilder.GetContext();
            _clubId  = _context.Clubs.First().Id;
            _mapper  = MapperBuilder.GetSailScoresMapper();

            _service = new SailScores.Core.Services.CompetitorService(
                _context,
                _mapper
                );
        }
        public async Task <IHttpActionResult> CreateNewCompetition([FromBody] CompetitionCreationInfoDTO competitionSettings)
        {
            try
            {
                using (var competitionService = new CompetitionService())
                    using (var competitorService = new CompetitorService(competitionService.DbContext))
                    {
                        var competition = competitionService.CreateNewCompetition(competitionSettings.Options);
                        competitorService.InsertNewCompetitors(competition, competitionSettings.Competitors);

                        await competitionService.DbContext.SaveChangesAsync();

                        return(Ok(competition.Id));
                    }
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
예제 #9
0
파일: Shared.cs 프로젝트: mkozma/OR-Results
        public static string GetClubImage(int SI, CompetitorService competitorService)
        {
            string clubImagePath = string.Empty;

            var club = competitorService.Get(SI).Club;

            if (!isImageFileExists(club + Constants.IMAGE_SIZE))
            {
                return(clubImagePath = String.Format("{0}", "OV" + Constants.IMAGE_SIZE + Constants.IMAGE_FILE_EXTENSION));
            }

            if (club == "%20")
            {
                return("spacer");
            }

            var hasSpace = club.Contains(" ");

            club = (hasSpace) ? club.Replace(" ", "%20") : club;
            return(clubImagePath = String.Format("{0}", club + Constants.IMAGE_SIZE + Constants.IMAGE_FILE_EXTENSION));
        }