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; } }
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 })); }
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); } }
public async Task <IActionResult> ApiScopeDelete(ApiScopeDto apiScope) { await _apiScopeService.DeleteApiScopeAsync(apiScope); SuccessNotification(_localizer["SuccessDeleteApiScope"], _localizer["SuccessTitle"]); return(RedirectToAction(nameof(ApiScopes))); }
/// <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)); })); }
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); }
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)); }
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)); }
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)); } }
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); }
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()); }
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)); } }
public ApiScopeDeletedEvent(ApiScopeDto apiScope) { ApiScope = apiScope; }
public ApiScopeAddedEvent(ApiScopeDto apiScope) { ApiScope = apiScope; }
public static ApiScope ToEntity(this ApiScopeDto apiScopeDto, ApiScope apiScope = null) { return(Mapper.Map <ApiScopeDto, ApiScope>(apiScopeDto, apiScope)); }
public ApiScopeUpdatedEvent(ApiScopeDto originalApiScope, ApiScopeDto apiScope) { OriginalApiScope = originalApiScope; ApiScope = apiScope; }
public static ApiScope ToEntity(this ApiScopeDto resource) { return(resource == null ? null : Mapper.Map <ApiScope>(resource)); }
protected Task OnResetSearchAsync(ApiScopeDto dto) { dto.Name = null; return(Task.CompletedTask); }
public virtual async Task <bool> CanInsertApiScopeAsync(ApiScopeDto apiScopeDto) { var apiScope = apiScopeDto.ToEntity(); return(await ApiScopeRepository.CanInsertApiScopeAsync(apiScope)); }
public IActionResult AddApiScope([FromBody] ApiScopeDto ApiScopeDto) { this.service.AddApiScope(ApiScopeDto); return(Success()); }
public virtual ApiScopeDto BuildApiScopeViewModel(ApiScopeDto apiScope) { ComboBoxHelpers.PopulateValuesToList(apiScope.UserClaimsItems, apiScope.UserClaims); return(apiScope); }
public IActionResult UpdateApiScope(int id, [FromBody] ApiScopeDto ApiScopeDto) { this.service.UpdateApiScope(id, ApiScopeDto); return(Success()); }
public IActionResult GetApiScope(int?id) { ApiScopeDto data = this.service.GetApiScopeDto(id); return(Success(data)); }
public ApiScopeRequestedEvent(ApiScopeDto apiScopes) { ApiScopes = apiScopes; }
public async Task <AjaxResult> CreateApiScopeAsync([FromBody] ApiScopeDto dto) { return((await _apiScopeService.CreateApiScopeAsync(dto)).ToAjaxResult()); }