Example #1
0
        public async Task AddEditTeamRosterClaim(TournamentTeam team, long accountId)
        {
            if (!Authorizer.HasClaim(EditTeamRoster, team))
            {
                throw new UnauthorizedAccessException();
            }

            var account = await Context.Accounts.FindAsync(accountId);

            if (account is null)
            {
                throw new KeyNotFoundException();
            }

            var claim = EditTeamRoster.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();
        }
Example #2
0
        public async Task RemoveEditTeamRosterClaim(TournamentTeam team, long accountId)
        {
            if (!Authorizer.HasClaim(EditTeamRoster, team))
            {
                throw new UnauthorizedAccessException();
            }

            var scoped = EditTeamRoster.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();
        }