public virtual async Task <IdentityResourceDto> UpdateAsync(Guid id, IdentityResourceCreateOrUpdateDto input)
        {
            var identityResource = await IdentityResourceRepository.GetAsync(id);

            await UpdateApiResourceByInputAsync(identityResource, input);

            identityResource = await IdentityResourceRepository.UpdateAsync(identityResource);

            await CurrentUnitOfWork.SaveChangesAsync();

            return(ObjectMapper.Map <IdentityResource, IdentityResourceDto>(identityResource));
        }
        public virtual async Task <IdentityResourceDto> CreateAsync(IdentityResourceCreateOrUpdateDto input)
        {
            var identityResourceExists = await IdentityResourceRepository.CheckNameExistAsync(input.Name);

            if (identityResourceExists)
            {
                throw new UserFriendlyException(L[AbpIdentityServerErrorConsts.IdentityResourceNameExisted, input.Name]);
            }
            var identityResource = new IdentityResource(GuidGenerator.Create(), input.Name, input.DisplayName,
                                                        input.Description, input.Enabled, input.Required, input.Emphasize,
                                                        input.ShowInDiscoveryDocument);

            await UpdateApiResourceByInputAsync(identityResource, input);

            await CurrentUnitOfWork.SaveChangesAsync();

            identityResource = await IdentityResourceRepository.InsertAsync(identityResource);

            return(ObjectMapper.Map <IdentityResource, IdentityResourceDto>(identityResource));
        }
        protected virtual async Task UpdateApiResourceByInputAsync(IdentityResource identityResource, IdentityResourceCreateOrUpdateDto input)
        {
            if (!string.Equals(identityResource.Name, input.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                identityResource.Name = input.Name;
            }
            if (!string.Equals(identityResource.Description, input.Description, StringComparison.InvariantCultureIgnoreCase))
            {
                identityResource.Description = input.Description;
            }
            if (!string.Equals(identityResource.DisplayName, input.DisplayName, StringComparison.InvariantCultureIgnoreCase))
            {
                identityResource.DisplayName = input.DisplayName;
            }
            identityResource.Emphasize = input.Emphasize;
            identityResource.Enabled   = input.Enabled;
            identityResource.Required  = input.Required;
            identityResource.ShowInDiscoveryDocument = input.ShowInDiscoveryDocument;

            if (await IsGrantAsync(AbpIdentityServerPermissions.IdentityResources.ManageClaims))
            {
                // 删除不存在的UserClaim
                identityResource.UserClaims.RemoveAll(claim => input.UserClaims.Contains(claim.Type));
                foreach (var inputClaim in input.UserClaims)
                {
                    var userClaim = identityResource.FindUserClaim(inputClaim);
                    if (userClaim == null)
                    {
                        identityResource.AddUserClaim(inputClaim);
                    }
                }
            }

            if (await IsGrantAsync(AbpIdentityServerPermissions.IdentityResources.ManageProperties))
            {
                // 删除不存在的Property
                identityResource.Properties.RemoveAll(scope => !input.Properties.ContainsKey(scope.Key));
                foreach (var inputProp in input.Properties)
                {
                    identityResource.Properties[inputProp.Key] = inputProp.Value;
                }
            }
        }
 public virtual async Task <IdentityResourceDto> UpdateAsync(Guid id, IdentityResourceCreateOrUpdateDto input)
 {
     return(await IdentityResourceAppService.UpdateAsync(id, input));
 }