Ejemplo n.º 1
0
        public void UpdateIdentityResource(int id, IdentityResourceDto identityResourceDto)
        {
            var transaction = this.Session.BeginTransaction();

            try
            {
                var identityResource = this.Session.Get <IdentityResource>(id);
                identityResource = identityResourceDto.ToEntity(identityResource);
                this.Session.Update(identityResource);
                this.Session.CreateQuery("delete from IdentityClaim where IdentityResourceId=:IdentityResourceId")
                .SetInt32("IdentityResourceId", id)
                .ExecuteUpdate();
                identityResourceDto.UserClaims.ForEach(claimType =>
                {
                    IdentityClaim identityClaim      = new IdentityClaim();
                    identityClaim.IdentityResourceId = identityResource.Id;
                    identityClaim.Type = claimType;
                    this.Session.Save(identityClaim);
                });
                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public async Task <ApiResponse> CreateIdentityResourceAsync(IdentityResourceDto identityResourceDto)
        {
            var identityResource = identityResourceDto.ToEntity();
            await _configurationDbContext.IdentityResources.AddAsync(identityResource);

            await _configurationDbContext.SaveChangesAsync();

            return(new ApiResponse(Status200OK, L["Identity Resource {0} created", identityResourceDto.Name], identityResourceDto));
        }
Ejemplo n.º 3
0
        public virtual async Task <int> DeleteIdentityResourceAsync(IdentityResourceDto identityResource)
        {
            var resource = identityResource.ToEntity();

            var deleted = await IdentityResourceRepository.DeleteIdentityResourceAsync(resource);

            await AuditEventLogger.LogEventAsync(new IdentityResourceDeletedEvent(identityResource));

            return(deleted);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 修改身份资源
        /// </summary>
        /// <param name="dto">身份资源参数</param>
        public async Task UpdateAsync(IdentityResourceDto dto)
        {
            var entity = dto.ToEntity();

            await ValidateUpdateAsync(entity);

            await IdentityResourceRepository.UpdateAsync(entity);

            await UnitOfWork.CommitAsync();
        }
Ejemplo n.º 5
0
        public async Task <int> UpdateIdentityResourceAsync(IdentityResourceDto identityResource)
        {
            var canInsert = await CanInsertIdentityResourceAsync(identityResource);

            if (!canInsert)
            {
                throw new UserFriendlyViewException(string.Format(_identityResourceServiceResources.IdentityResourceExistsValue().Description, identityResource.Name), _identityResourceServiceResources.IdentityResourceExistsKey().Description, identityResource);
            }

            var resource = identityResource.ToEntity();

            return(await _identityResourceRepository.UpdateIdentityResourceAsync(resource));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 创建身份资源
        /// </summary>
        /// <param name="dto">身份资源参数</param>
        public async Task <Guid> CreateAsync(IdentityResourceDto dto)
        {
            var entity = dto.ToEntity();

            await ValidateCreateAsync(entity);

            entity.Init();
            await IdentityResourceRepository.AddAsync(entity);

            await UnitOfWork.CommitAsync();

            return(entity.Id);
        }
Ejemplo n.º 7
0
        public virtual async Task <int> AddIdentityResourceAsync(IdentityResourceDto identityResource)
        {
            var canInsert = await CanInsertIdentityResourceAsync(identityResource);

            if (!canInsert)
            {
                throw new UserFriendlyViewException(string.Format(IdentityResourceServiceResources.IdentityResourceExistsValue().Description, identityResource.Name), IdentityResourceServiceResources.IdentityResourceExistsKey().Description, identityResource);
            }

            var resource = identityResource.ToEntity();

            var saved = await IdentityResourceRepository.AddIdentityResourceAsync(resource);

            await AuditEventLogger.LogEventAsync(new IdentityResourceAddedEvent(identityResource));

            return(saved);
        }
Ejemplo n.º 8
0
        public async Task <ApiResponse> UpdateIdentityResourceAsync(IdentityResourceDto identityResourceDto)
        {
            //Name is not the primary key, but a unique index and IdentityResourceDto does not contain the real key Id.
            //So in UI I have to use Name as a key and I make it read only.
            var identityResource = await _configurationDbContext.IdentityResources.SingleOrDefaultAsync(i => i.Name == identityResourceDto.Name);

            if (identityResource == null)
            {
                return(new ApiResponse(Status400BadRequest, L["The Identity resource {0} doesn't exist", identityResourceDto.Name]));
            }

            _configurationDbContext.IdentityResources.Remove(identityResource);

            _configurationDbContext.IdentityResources.Add(identityResourceDto.ToEntity());
            await _configurationDbContext.SaveChangesAsync();

            return(new ApiResponse(Status200OK, L["Identity Resource {0} updated", identityResourceDto.Name], identityResourceDto));
        }
Ejemplo n.º 9
0
        public void AddIdentityResource(IdentityResourceDto identityResourceDto)
        {
            var transaction = this.Session.BeginTransaction();

            try
            {
                var identityResource = identityResourceDto.ToEntity();
                this.Session.Save(identityResource);
                identityResourceDto.UserClaims.ForEach(claimType =>
                {
                    IdentityClaim identityClaim      = new IdentityClaim();
                    identityClaim.IdentityResourceId = identityResource.Id;
                    identityClaim.Type = claimType;
                    this.Session.Save(identityClaim);
                });
                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
        }
Ejemplo n.º 10
0
        public async Task <int> DeleteIdentityResourceAsync(IdentityResourceDto identityResource)
        {
            var resource = identityResource.ToEntity();

            return(await _identityResourceRepository.DeleteIdentityResourceAsync(resource));
        }
Ejemplo n.º 11
0
        public async Task <bool> CanInsertIdentityResourceAsync(IdentityResourceDto identityResource)
        {
            var resource = identityResource.ToEntity();

            return(await _identityResourceRepository.CanInsertIdentityResourceAsync(resource));
        }