public async Task <ServiceResult> TeamApplyToTournament(Guid teamId, DTO.Tournament.TeamTournamentApplicationRequest teamApplication) { var result = new ServiceResult(); var tournament = await this.alexandriaContext.Tournaments.Include(t => t.TournamentApplications).ThenInclude(t => t.TournamentApplicationQuestionAnswers).FirstOrDefaultAsync(t => t.Id == teamApplication.TournamentId); if (tournament == null) { result.Error = Shared.ErrorKey.Tournament.NotFound; return(result); } if (!tournament.CanSignup) { result.Error = Shared.ErrorKey.Tournament.ApplicationsClosed; return(result); } var application = tournament.TournamentApplications.FirstOrDefault(ta => ta.TeamId == teamId); if (application == null) { application = await this.DangerouslyCreateTournamentApplication(teamId, teamApplication); } else { application = await this.DangerouslyUpdateTournamentApplication(application, teamApplication.Answers); } result.Succeed(); return(result); }
public async Task <Svalbard.OperationResult> ApplyToTournament([FromBody] DTO.Tournament.TeamTournamentApplicationRequest payload) { var result = await tournamentService.TeamApplyToTournament(this.resourceId, payload); if (result.Success) { return(new Svalbard.OperationResult(201)); } return(new Svalbard.OperationResult(result.Error)); }
private Task <EF.Models.TournamentApplication> DangerouslyCreateTournamentApplication(Guid teamId, DTO.Tournament.TeamTournamentApplicationRequest teamApplication) { var application = new EF.Models.TournamentApplication(teamId, teamApplication.TournamentId); foreach (var answer in teamApplication.Answers) { var questionAnswer = new EF.Models.TournamentApplicationQuestionAnswer(answer.Id, answer.Answer); application.AddAnswer(questionAnswer); } application.Initialize(); this.alexandriaContext.TournamentApplications.Add(application); return(Task.FromResult(application)); }