public async Task <CompetitionResponse> AddAdminToCompetition(Guid userId, Guid competitionId) { var existingAdmin = await _adminRepo.Get(userId, competitionId); existingAdmin.EnsureDoesNotExist(); var existingAdminRequest = await _adminRequestRepo.Get(userId, competitionId); existingAdminRequest.EnsureExists("Admin request not found."); _adminRepo.Create(new Admin(userId, competitionId)); _adminRequestRepo.Delete(existingAdminRequest); await _adminRepo.Save(); //return competition with admin information var competition = await _competitionRepo.GetWithInfo(competitionId); return(new CompetitionResponse(competition, true, userId)); }
//note - for admin actions, competition can't be null or won't pass authorization public async Task <CompetitionResponse> GetCompetition(Guid userId, Guid competitionId) { var admin = await _adminRepo.Get(userId, competitionId); var competition = await _competitionRepo.GetWithInfo(competitionId); competition.EnsureExists("Competition not found."); if (admin != null) { return(new CompetitionResponse(competition, true, userId)); } var participant = competition.Participants.FirstOrDefault(x => x.UserId == userId); if (participant != null || !competition.IsPrivate) { return(new CompetitionResponse(competition, false, userId)); } throw new ApiError(403); }