public void UpdateApiScope(int id, ApiScopeDto apiScopeDto)
        {
            ApiScope apiScope = this.Session.Get <ApiScope>(id);

            apiScope = apiScopeDto.ToEntity(apiScope);
            if (!CanInsertApiScope(apiScope))
            {
                throw new FluentValidationException("ApiScope名称重复。");
            }
            var transaction = this.Session.BeginTransaction();

            try
            {
                this.Session.Update(apiScope);

                this.Session.CreateQuery("delete from ApiScopeClaim where ApiScopeId=:ApiScopeId")
                .SetInt32("ApiScopeId", id)
                .ExecuteUpdate();

                apiScopeDto.UserClaims.ForEach(type =>
                {
                    ApiScopeClaim apiScopeClaim = new ApiScopeClaim();
                    apiScopeClaim.ApiScopeId    = apiScope.Id;
                    apiScopeClaim.Type          = type;
                    this.Session.Save(apiScopeClaim);
                });
                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
        }
        public void AddApiScope(ApiScopeDto apiScopeDto)
        {
            ApiScope apiScope = apiScopeDto.ToEntity();

            if (!CanInsertApiScope(apiScope))
            {
                throw new FluentValidationException("ApiScope名称重复。");
            }
            var transaction = this.Session.BeginTransaction();

            try
            {
                this.Session.Save(apiScope);
                apiScopeDto.UserClaims.ForEach(type =>
                {
                    ApiScopeClaim apiScopeClaim = new ApiScopeClaim();
                    apiScopeClaim.ApiScopeId    = apiScope.Id;
                    apiScopeClaim.Type          = type;
                    this.Session.Save(apiScopeClaim);
                });
                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                throw ex;
            }
        }
Exemple #3
0
        public virtual async Task <int> DeleteApiScopeAsync(ApiScopeDto apiScope)
        {
            var scope = apiScope.ToEntity();

            var deleted = await ApiScopeRepository.DeleteApiScopeAsync(scope);

            await AuditEventLogger.LogEventAsync(new ApiScopeDeletedEvent(apiScope));

            return(deleted);
        }
Exemple #4
0
        public virtual async Task <int> AddApiScopeAsync(ApiScopeDto apiScope)
        {
            var canInsert = await CanInsertApiScopeAsync(apiScope);

            if (!canInsert)
            {
                throw new UserFriendlyViewException(string.Format(ApiScopeServiceResources.ApiScopeExistsValue().Description, apiScope.Name), ApiScopeServiceResources.ApiScopeExistsKey().Description, apiScope);
            }

            var scope = apiScope.ToEntity();

            var added = await ApiScopeRepository.AddApiScopeAsync(scope);

            await AuditEventLogger.LogEventAsync(new ApiScopeAddedEvent(apiScope));

            return(added);
        }
Exemple #5
0
        public virtual async Task <bool> CanInsertApiScopeAsync(ApiScopeDto apiScopeDto)
        {
            var apiScope = apiScopeDto.ToEntity();

            return(await ApiScopeRepository.CanInsertApiScopeAsync(apiScope));
        }