Пример #1
0
        public async Task <IActionResult> Delete(string id, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            var scope = await _scopeRepository.Get(id, cancellationToken).ConfigureAwait(false);

            if (scope == null)
            {
                return(BadRequest(
                           new ErrorDetails
                {
                    Title = ErrorCodes.InvalidRequest,
                    Detail = string.Format(Strings.TheScopeDoesntExist, id),
                    Status = HttpStatusCode.BadRequest
                }));
            }

            var deleted = await _scopeRepository.Delete(scope, CancellationToken.None).ConfigureAwait(false);

            return(deleted
                ? (IActionResult)NoContent()
                : BadRequest(
                       new ErrorDetails
            {
                Title = ErrorCodes.InvalidRequest,
                Detail = string.Format(Strings.TheScopeDoesntExist, id),
                Status = HttpStatusCode.BadRequest
            }));
        }
Пример #2
0
 private async Task DeleteAsync(Scope scope)
 {
     if (scope != null)
     {
         _scopeRepository.Delete(scope);
         await _scopeRepository.SaveAsync();
     }
 }
        public async Task <bool> Execute(string scopeId)
        {
            _umaServerEventSource.StartToRemoveScope(scopeId);
            if (string.IsNullOrWhiteSpace(scopeId))
            {
                throw new ArgumentNullException(nameof(scopeId));
            }

            Scope scope = null;

            try
            {
                scope = await _scopeRepository.Get(scopeId);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeRetrieved,
                                           ex);
            }

            if (scope == null)
            {
                return(false);
            }

            try
            {
                await _scopeRepository.Delete(scopeId);

                _umaServerEventSource.FinishToRemoveScope(scopeId);
                return(true);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeRemoved,
                                           ex);
            }
        }