// TODO: Withdraw feature //public async Task WithdrawTeamAsync (long teamId) //{ // var existing = await Context.TournamentTeams // .Include(t => t.Participants) // .Where(t => t.TeamId == teamId) // .SingleOrDefaultAsync(); //} public async Task AddEditTeamInfoClaim(TournamentTeam team, long accountId) { if (!Authorizer.HasClaim(EditTeamInfo, team)) { throw new UnauthorizedAccessException(); } var account = await Context.Accounts.FindAsync(accountId); if (account is null) { throw new KeyNotFoundException(); } var claim = EditTeamInfo.ForTeam(team.TeamId); claim.AccountId = accountId; if (await Context.Claims.Where(c => c.Title == claim.Title && c.AccountId == claim.AccountId && c.Value == claim.Value).AnyAsync()) { // Already exists return; } Context.Claims.Add(claim); await Context.SaveChangesAsync(); }
public async Task RemoveEditTeamInfoClaim(TournamentTeam team, long accountId) { if (!Authorizer.HasClaim(EditTeamInfo, team)) { throw new UnauthorizedAccessException(); } var scoped = EditTeamInfo.ForTeam(team.TeamId); var claims = Context.Claims .Where(c => c.AccountId == accountId && c.Title == scoped.Title && c.Value == scoped.Value) .AsEnumerable(); Context.Claims.RemoveRange(claims); await Context.SaveChangesAsync(); }