コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
        public async Task <IActionResult> ApiScope(ApiScopeDto apiScope)
        {
            if (!ModelState.IsValid)
            {
                return(View(apiScope));
            }

            _apiScopeService.BuildApiScopeViewModel(apiScope);

            int apiScopeId;

            if (apiScope.Id == 0)
            {
                apiScopeId = await _apiScopeService.AddApiScopeAsync(apiScope);
            }
            else
            {
                apiScopeId = apiScope.Id;
                await _apiScopeService.UpdateApiScopeAsync(apiScope);
            }

            SuccessNotification(string.Format(_localizer["SuccessAddApiScope"], apiScope.Name), _localizer["SuccessTitle"]);

            return(RedirectToAction(nameof(ApiScope), new { Scope = apiScopeId }));
        }
コード例 #4
0
        protected async Task <bool> OnSaveAsync(ApiScopeDto dto)
        {
            ResultModel <string> result = new ResultModel <string>();
            var model = new ApiScopeEditDto()
            {
                Enabled     = dto.Enabled,
                Name        = dto.Name,
                DisplayName = dto.DisplayName,
                Description = dto.Description
            };

            if (dto.Id == null)
            {
                model.Id = 0;
                result   = await ApiScopeService.AddApiScope(model);
            }
            else
            {
                model.Id = dto.Id;
                result   = await ApiScopeService.EditApiScope(model);
            }
            if (result.status.code == ResultCode.Success)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
        public async Task <IActionResult> ApiScopeDelete(ApiScopeDto apiScope)
        {
            await _apiScopeService.DeleteApiScopeAsync(apiScope);

            SuccessNotification(_localizer["SuccessDeleteApiScope"], _localizer["SuccessTitle"]);

            return(RedirectToAction(nameof(ApiScopes)));
        }
コード例 #6
0
        /// <summary>
        /// 异步创建API范围
        /// </summary>
        /// <param name="dtos"></param>
        /// <returns></returns>

        public Task <OperationResponse> CreateApiScopeAsync(ApiScopeDto dto)
        {
            dto.NotNull(nameof(dto));
            return(_apiScopeRepository.InsertAsync(dto, async(dto1) =>
            {
                MessageBox.ShowIf($"指定【{dto.Name}】Api范围已存在", await this.CheckApiResourceIsExist(dto1.Id, dto1.Name));
            }));
        }
コード例 #7
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);
        }
コード例 #8
0
        public async Task <ResultModel> GetById(int id)
        {
            var apiScope = await _userDatabaseContext.ApiScopes.Where(x => x.Id == id)
                           .Include(x => x.UserClaims)
                           //.Include(x => x.Properties)
                           .FirstOrDefaultAsync();

            if (apiScope == null)
            {
                return(new ResultModel(ResultCode.Fail, "没有对应API域"));
            }


            List <ApiScopeClaimDto> apiScopeClaimDtos = new List <ApiScopeClaimDto>();

            foreach (var item in apiScope.UserClaims)
            {
                apiScopeClaimDtos.Add(new ApiScopeClaimDto
                {
                    ScopeId = item.ScopeId,
                    Id      = item.Id,
                    Type    = item.Type
                });
            }

            //List<ApiScopePropertyDto> apiScopePropertyDtos = new List<ApiScopePropertyDto>();
            //foreach (var item in apiScope.Properties)
            //{
            //    apiScopePropertyDtos.Add(new ApiScopePropertyDto
            //    {
            //        Id = item.Id,
            //        Key = item.Key,
            //        Value = item.Value,
            //        ScopeId = item.ScopeId
            //    });
            //}

            var apiScopeDto = new ApiScopeDto
            {
                Id                      = apiScope.Id,
                Enabled                 = apiScope.Enabled,
                Name                    = apiScope.Name,
                DisplayName             = apiScope.Name,
                Description             = apiScope.Description,
                Required                = apiScope.Required,
                Emphasize               = apiScope.Emphasize,
                ShowInDiscoveryDocument = apiScope.ShowInDiscoveryDocument,
                UserClaims              = apiScopeClaimDtos,
                //Properties = apiScopePropertyDtos
            };

            return(new ResultModel(ResultCode.Success, apiScopeDto));
        }
コード例 #9
0
        public async Task <IActionResult> CreateOrUpdateApiScopeAsync(ApiScopeDto dto)
        {
            var result = await apiScopeService.CreateOrUpdateApiScopeAsync(dto).ConfigureAwait(false);

            if (result.Succeeded)
            {
                return(Ok());
            }

            ModelState.AddModelError(string.Empty, result.ErrorMessage);
            return(BadRequest(ModelState));
        }
コード例 #10
0
        public async Task <IActionResult> ApiScope(int?id)
        {
            if (id == null)
            {
                var apiScopeDto = new ApiScopeDto();

                return(View(apiScopeDto));
            }
            else
            {
                var apiScopeDto = await _apiScopeService.GetApiScopeAsync(id.Value);

                return(View(apiScopeDto));
            }
        }
コード例 #11
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);
        }
コード例 #12
0
        public ApiScopeDto GetApiScopeDto(int?id)
        {
            ApiScopeDto apiScopeDto = new ApiScopeDto();

            if (!id.HasValue)
            {
                return(apiScopeDto);
            }
            if (id.Value <= 0)
            {
                return(apiScopeDto);
            }
            ApiScope apiScope = this.Session.Get <ApiScope>(id.Value);

            apiScope.UserClaims = this.Session.CreateCriteria <ApiScopeClaim>()
                                  .Add(NHibernate.Criterion.Restrictions.Eq("ApiScopeId", id.Value))
                                  .List <ApiScopeClaim>()
                                  .ToList();

            return(apiScope.ToModel());
        }
コード例 #13
0
        public async Task <IActionResult> ApiScope(string id)
        {
            if (id.IsNotPresentedValidNumber())
            {
                return(NotFound());
            }

            if (id == default)
            {
                var apiScopeDto = new ApiScopeDto();

                return(View(apiScopeDto));
            }
            else
            {
                int.TryParse(id, out var apiScopeId);
                var apiScopeDto = await _apiScopeService.GetApiScopeAsync(apiScopeId);

                return(View(apiScopeDto));
            }
        }
コード例 #14
0
 public ApiScopeDeletedEvent(ApiScopeDto apiScope)
 {
     ApiScope = apiScope;
 }
コード例 #15
0
 public ApiScopeAddedEvent(ApiScopeDto apiScope)
 {
     ApiScope = apiScope;
 }
コード例 #16
0
 public static ApiScope ToEntity(this ApiScopeDto apiScopeDto, ApiScope apiScope = null)
 {
     return(Mapper.Map <ApiScopeDto, ApiScope>(apiScopeDto, apiScope));
 }
コード例 #17
0
 public ApiScopeUpdatedEvent(ApiScopeDto originalApiScope, ApiScopeDto apiScope)
 {
     OriginalApiScope = originalApiScope;
     ApiScope         = apiScope;
 }
コード例 #18
0
 public static ApiScope ToEntity(this ApiScopeDto resource)
 {
     return(resource == null ? null : Mapper.Map <ApiScope>(resource));
 }
コード例 #19
0
 protected Task OnResetSearchAsync(ApiScopeDto dto)
 {
     dto.Name = null;
     return(Task.CompletedTask);
 }
コード例 #20
0
        public virtual async Task <bool> CanInsertApiScopeAsync(ApiScopeDto apiScopeDto)
        {
            var apiScope = apiScopeDto.ToEntity();

            return(await ApiScopeRepository.CanInsertApiScopeAsync(apiScope));
        }
コード例 #21
0
 public IActionResult AddApiScope([FromBody] ApiScopeDto ApiScopeDto)
 {
     this.service.AddApiScope(ApiScopeDto);
     return(Success());
 }
コード例 #22
0
        public virtual ApiScopeDto BuildApiScopeViewModel(ApiScopeDto apiScope)
        {
            ComboBoxHelpers.PopulateValuesToList(apiScope.UserClaimsItems, apiScope.UserClaims);

            return(apiScope);
        }
コード例 #23
0
 public IActionResult UpdateApiScope(int id, [FromBody] ApiScopeDto ApiScopeDto)
 {
     this.service.UpdateApiScope(id, ApiScopeDto);
     return(Success());
 }
コード例 #24
0
        public IActionResult GetApiScope(int?id)
        {
            ApiScopeDto data = this.service.GetApiScopeDto(id);

            return(Success(data));
        }
コード例 #25
0
 public ApiScopeRequestedEvent(ApiScopeDto apiScopes)
 {
     ApiScopes = apiScopes;
 }
コード例 #26
0
 public async Task <AjaxResult> CreateApiScopeAsync([FromBody] ApiScopeDto dto)
 {
     return((await _apiScopeService.CreateApiScopeAsync(dto)).ToAjaxResult());
 }