示例#1
0
        public async Task <IActionResult> Update(
            string name,
            [FromForm] Scope scope,
            CancellationToken cancellationToken)
        {
            if (scope == null)
            {
                throw new ArgumentNullException(nameof(scope));
            }

            scope = scope with {
                Name = name
            };
            return(await _scopeRepository.Update(scope, cancellationToken).ConfigureAwait(false)
                ? RedirectToAction("GetAll", "Scopes")
                : new StatusCodeResult(StatusCodes.Status500InternalServerError));
        }
        public async Task <bool> Execute(UpdateScopeParameter updateScopeParameter)
        {
            if (updateScopeParameter == null)
            {
                throw new ArgumentNullException(nameof(updateScopeParameter));
            }

            Scope scope = null;

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

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

            scope = new Scope
            {
                Id      = updateScopeParameter.Id,
                IconUri = updateScopeParameter.IconUri,
                Name    = updateScopeParameter.Name
            };
            _scopeParameterValidator.CheckScopeParameter(scope);

            try
            {
                await _scopeRepository.Update(scope);

                return(true);
            }
            catch (Exception ex)
            {
                throw new BaseUmaException(ErrorCodes.InternalError,
                                           ErrorDescriptions.TheScopeCannotBeUpdated,
                                           ex);
            }
        }