예제 #1
0
        public async Task <Scope> UpdateAsync(Scope updatedScope)
        {
            var scope = await _scopeRepository.FindAsync(updatedScope.ScopeId);

            if (scope == null)
            {
                throw new BadRequestException("Scope does not exist.");
            }

            return(await UpdateAsync(scope, updatedScope));
        }
예제 #2
0
        public async Task <Scope> FindAsync(Guid scopeId)
        {
            var scope = await _scopeRepository.FindAsync(scopeId);

            if (scope == null)
            {
                throw new NotFoundException();
            }

            return(scope);
        }
예제 #3
0
        private async Task <List <Scope> > AddScopeRelationAsync(Role role, Guid scopeId)
        {
            if (!role.Scopes.Any(s => s.ScopeId == scopeId))
            {
                var scope = await _scopeRepository.FindAsync(scopeId);

                if (scope == null)
                {
                    throw new NotFoundException();
                }

                role.Scopes.Add(scope);
                await _roleRepository.SaveAsync();
            }

            return(role.Scopes.ToList());
        }
예제 #4
0
        private async Task <List <Scope> > DeleteScopeRelationAsync(Role role, Guid scopeId)
        {
            if (role.Scopes.Any(s => s.ScopeId == scopeId))
            {
                var scope = await _scopeRepository.FindAsync(scopeId);

                if (scope == null)
                {
                    throw new BadRequestException("Scope not found.");
                }

                role.Scopes.Remove(scope);
                await _roleRepository.SaveAsync();
            }

            return(role.Scopes.ToList());
        }
예제 #5
0
        public async Task DeleteAsync(Guid scopeId)
        {
            var scope = await _scopeRepository.FindAsync(scopeId);

            await DeleteAsync(scope);
        }