public MatchDto(TournamentReadDto tournamentDto, UserReadDto player1, UserReadDto player2, int round) { TournamentDto = tournamentDto; Player1 = player1; Player2 = player2; Round = round; }
public void SetTournament(TournamentReadDto tournament, List <MatchDto> matchesInRound) { foreach (var matchDto in matchesInRound) { matchDto.TournamentDto = tournament; } }
public TournamentCourse(List <UserReadDto> users, TournamentReadDto tournamentDto, UserReadDto byeUser) { UsersDto = users; TournamentDto = tournamentDto; _byeUser = byeUser; RoundsNumber = (int)Math.Ceiling(Math.Log2(TournamentDto.DrawSize)); InitNameOfRound(); DrawFirstRound(); }
/*public void UpdateMatches(int id, TournamentReadDto tournament, UserReadDto player1, UserReadDto player2, * int round, Winner winner, string result) * { * Matches.Add(new MatchDto(id, tournament, player1, player2, winner, result, round)); * } * * public void UpdateMatches(MatchDto matchDto) * { * Matches.Add(matchDto); * }*/ public void UpdateOthers(TournamentReadDto tournament, int round) { Matches.RemoveAll(m => m.Id == 0); TournamentDto = tournament; CurrentRound = round; RoundsNumber = (int)Math.Ceiling(Math.Log2(TournamentDto.DrawSize)); InitNameOfRound(); if (CurrentRound == RoundsNumber) //tournament finished { IsFinished = true; } else { CreateNextMatches(); } }
public ActionResult CompletedTournamentDetail(int id) { TournamentReadDto tournamentDto = _mapper.Map <TournamentReadDto>(_tournamentRepository.GetTournamentById(id)); TournamentCourse tournamentCourse = new TournamentCourse(tournamentDto); List <Match> matches = _repository.GetMatchesByTournamentId(id); foreach (var match in matches) { match.Player1 = _userRepository.GetUserById(match.Player1.Id); match.Player2 = _userRepository.GetUserById(match.Player2.Id); } tournamentCourse.Matches = matches.Select(match => _mapper.Map <MatchDto>(match)).ToList(); tournamentCourse.RoundsNumber = (int)Math.Ceiling(Math.Log2(tournamentDto.DrawSize)); tournamentCourse.IsFinished = tournamentDto.Completed; tournamentCourse.CurrentRound = _repository.GetTournamentRound(tournamentDto.Id); return(View(tournamentCourse)); }
public MatchDto(TournamentReadDto tournamentDto, UserReadDto player1, UserReadDto player2, int round, Winner winner) : this(tournamentDto, player1, player2, round) { Winner = winner; }
public TournamentCourse(TournamentReadDto tournamentDto) { TournamentDto = tournamentDto; RoundsNumber = (int)Math.Ceiling(Math.Log2(TournamentDto.DrawSize)); InitNameOfRound(); }
public IActionResult GetResultsTournament([FromForm] TournamentCourse tournamentCourse) { var tournamentId = int.Parse(Request.Form["TournamentId"]); Tournament tournament = _tournamentRepository.GetTournamentById(tournamentId); TournamentReadDto tournamentDto = _mapper.Map <TournamentReadDto>(tournament); if (tournamentCourse.Matches == null) //from /ongoingAll { tournamentCourse.TournamentDto = tournamentDto; tournamentCourse.Matches = _repository.GetMatchesByTournamentId(tournamentId) .Select(match => _mapper.Map <MatchDto>(match)).ToList(); tournamentCourse.updateOngoing(); return(View("/Views/CourseTournament/CourseTournament.cshtml", tournamentCourse)); } int round = 0; int numberOfMatches = tournamentCourse.Matches.Count; int currentRound = _repository.GetTournamentRound(tournamentId); for (int i = 0; i < numberOfMatches; i++) { int id = int.Parse(Request.Form["MatchDto[" + i + "].Id"]); Match match = _repository.GetMatchById(id); if (currentRound == match.Round) { if (match.Player1.Id == -1) { match.Winner = Winner.Two; } else if (match.Player2.Id == -1) { match.Winner = Winner.One; } else { match.Winner = tournamentCourse.Matches[i].Winner; } match.Result = tournamentCourse.Matches[i].Result; _repository.SaveChanges(); //update finished matches round = match.Round; //last round } MatchDto matchDto = _mapper.Map <MatchDto>(match); matchDto.TournamentDto = tournamentDto; tournamentCourse.Matches.Add(matchDto); } tournamentCourse.UpdateOthers(tournamentDto, round); if (!tournamentCourse.IsFinished) { var matches = tournamentCourse.GetMatchesInCurrentRound() .Select(match => _mapper.Map <Match>(match)).ToList(); foreach (var match in matches) { match.Tournament = tournament; _repository.DetachLocal(match, match.Id); _repository.SaveMatch(match); _repository.SaveChanges(); MatchDto matchDto = _mapper.Map <MatchDto>(match); tournamentCourse.Matches.Add(matchDto); } tournamentCourse.Matches.RemoveAll(m => m.Id == 0); } else { tournament.Completed = true; _tournamentRepository.SaveChanges(); return(RedirectToAction(nameof(CompletedTournamentDetail), new { id = tournamentDto.Id })); } return(View("/Views/CourseTournament/CourseTournament.cshtml", tournamentCourse)); }
public TournamentParticipants(TournamentReadDto tournament, List <UserReadDto> users, bool isRegistered) { TournamentDto = tournament; Users = users; IsRegistered = isRegistered; }