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 DisplayResults(Settings settings, CourseService courseService, CompetitorService competitorService) { _settings = settings; _courseService = courseService; _competitorService = competitorService; CalculateDataPerColumn(); CalculateDataInTables(); BuildDisplayTable(); }
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 })); } }
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 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()); } }
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)); }