Ejemplo n.º 1
0
        public virtual async Task <IdentityResourceDto> CreateAsync(IdentityResourceCreateUpdateDto input)
        {
            var existed = await _resourceRepository.CheckNameExistAsync(input.Name);

            if (existed)
            {
                throw new UserFriendlyException(L["EntityExisted", nameof(IdentityResource),
                                                  nameof(IdentityResource.Name),
                                                  input.Name]);
            }

            var identityResource = new IdentityResource(GuidGenerator.Create(), input.Name);

            identityResource = ObjectMapper.Map(input, identityResource);
            input.UserClaims.ForEach(x => identityResource.AddUserClaim(x));

            identityResource = await _resourceRepository.InsertAsync(identityResource, true);

            return(ObjectMapper.Map <IdentityResource, IdentityResourceDto>(identityResource));
        }
Ejemplo n.º 2
0
        public async Task <IdentityResourceDto> CreateAsync(CreateIdentityResourceInputDto input)
        {
            var nameExist = await _repository.CheckNameExistAsync(input.Name.Trim());

            if (nameExist)
            {
                throw new IdentityResourceNameNotAllowedDuplicateException(input.Name);
            }
            var identityResource = new IdentityResource(GuidGenerator.Create(), input.Name.Trim())
            {
                DisplayName             = input.DisplayName?.Trim(),
                Description             = input.Description?.Trim(),
                Enabled                 = input.Enabled,
                Required                = input.Required,
                Emphasize               = input.Emphasize,
                ShowInDiscoveryDocument = input.ShowInDiscoveryDocument
            };

            input.UserClaims.ForEach(x => identityResource.AddUserClaim(x));
            identityResource = await _repository.InsertAsync(identityResource);

            return(MapToGetOutputDto(identityResource));
        }
        public async Task <IdentityResourceDto> CreateAsync(CreateIdentityResourceInputDto input)
        {
            var nameExist = await _repository.CheckNameExistAsync(input.Name.Trim());

            if (nameExist)
            {
                throw new IdentityResourceNameNotAllowedDuplicateException(input.Name);
            }
            var identityResource = new IdentityResource(GuidGenerator.Create(), input.Name.Trim())
            {
                DisplayName             = input.DisplayName?.Trim(),
                Description             = input.Description?.Trim(),
                Enabled                 = input.Enabled,
                Required                = input.Required,
                Emphasize               = input.Emphasize,
                ShowInDiscoveryDocument = input.ShowInDiscoveryDocument,
                Properties              = new Dictionary <string, string>()
            };

            input.UserClaims.ForEach(x => identityResource.AddUserClaim(x));

            if (input.Properties != null)
            {
                input.Properties.ForEach(x =>
                {
                    if (!identityResource.Properties.ContainsKey(x.Key))
                    {
                        identityResource.Properties.Add(x.Key, x.Value);
                    }
                });
            }

            identityResource = await _repository.InsertAsync(identityResource);

            return(MapToGetOutputDto(identityResource));
        }