public async Task <IActionResult> IdentityResourceDelete(IdentityResourceDto identityResource) { await _identityResourceService.DeleteIdentityResourceAsync(identityResource); SuccessNotification(_localizer["SuccessDeleteIdentityResource"], _localizer["SuccessTitle"]); return(RedirectToAction(nameof(IdentityResources))); }
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)); }
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); }
/// <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(); }
public async Task <IActionResult> IdentityResource(int id) { if (id == 0) { var identityResourceDto = new IdentityResourceDto(); return(View(identityResourceDto)); } var identityResource = await _identityResourceService.GetIdentityResourceAsync(id); return(View(identityResource)); }
public async Task <IActionResult> Delete(int id) { var identityResource = new IdentityResourceDto { Id = id }; await _identityResourceService.GetIdentityResourceAsync(identityResource.Id); await _identityResourceService.DeleteIdentityResourceAsync(identityResource); return(Ok()); }
public async Task <IActionResult> CreateOrUpdateIdentityResourceAsync(IdentityResourceDto dto) { var result = await identityResourceService.CreateOrUpdateIdentityResourceAsync(dto).ConfigureAwait(false); if (result.Succeeded) { return(Ok()); } ModelState.AddModelError(string.Empty, result.ErrorMessage); return(BadRequest(ModelState)); }
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)); }
/// <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); }
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); }
/// <summary> /// 转换为身份资源 /// </summary> private IdentityResource ToResource(IdentityResourceDto dto) { if (dto == null) { return(null); } var result = dto.MapTo <IdentityResource>(); result.Name = dto.Uri; result.DisplayName = dto.Name; result.Description = dto.Remark; if (dto.Claims != null && dto.Claims.Count > 0) { dto.Claims.ForEach(claim => result.UserClaims.Add(claim)); } return(result); }
public async Task <IActionResult> IdentityResource(string id) { if (id.IsNotPresentedValidNumber()) { return(NotFound()); } if (id == default) { var identityResourceDto = new IdentityResourceDto(); return(View(identityResourceDto)); } int.TryParse(id, out var identityResourceId); var identityResource = await _identityResourceService.GetIdentityResourceAsync(identityResourceId); return(View(identityResource)); }
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)); }
public async Task <IActionResult> IdentityResource(IdentityResourceDto identityResource) { if (!ModelState.IsValid) { return(View(identityResource)); } identityResource = _identityResourceService.BuildIdentityResourceViewModel(identityResource); if (identityResource.Id == 0) { await _identityResourceService.AddIdentityResourceAsync(identityResource); } else { await _identityResourceService.UpdateIdentityResourceAsync(identityResource); } SuccessNotification(string.Format(_localizer["SuccessAddIdentityResource"], identityResource.Name), _localizer["SuccessTitle"]); return(RedirectToAction(nameof(IdentityResources))); }
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; } }
//ToEntity public static IdentityResource ToEntity(this IdentityResourceDto resource) { return(resource == null ? null : Mapper.Map <IdentityResource>(resource)); }
public static IdentityResourceDto ToModel(this IdentityResource identityResource, IdentityResourceDto identityResourceDto) { return(Mapper.Map <IdentityResource, IdentityResourceDto>(identityResource, identityResourceDto)); }
public IActionResult UpdateIdentityResource(int id, [FromBody] IdentityResourceDto identityResourceDto) { this.service.UpdateIdentityResource(id, identityResourceDto); return(Success()); }
public IdentityResourceRequestedEvent(IdentityResourceDto identityResource) { IdentityResource = identityResource; }
public IdentityResourceDeletedEvent(IdentityResourceDto identityResource) { IdentityResource = identityResource; }
public IdentityResourceDto BuildIdentityResourceViewModel(IdentityResourceDto identityResource) { ComboBoxHelpers.PopulateValuesToList(identityResource.UserClaimsItems, identityResource.UserClaims); return(identityResource); }
public async Task <int> DeleteIdentityResourceAsync(IdentityResourceDto identityResource) { var resource = identityResource.ToEntity(); return(await _identityResourceRepository.DeleteIdentityResourceAsync(resource)); }
public IdentityResourceAddedEvent(IdentityResourceDto identityResource) { IdentityResource = identityResource; }
public async Task <ResultModel> GetById(int id) { ResultModel result = new ResultModel(); ResultStatus resultStatus = new ResultStatus(); result.status = resultStatus; var identityResource = await _userDatabaseContext.IdentityResources.Where(x => x.Id == id) .Include(x => x.UserClaims) .Include(x => x.Properties) .FirstOrDefaultAsync(); if (identityResource == null) { return(new ResultModel(ResultCode.Fail, "没有对应认证资源")); } var identityResourceDto = new IdentityResourceDto(); identityResourceDto.Id = identityResource.Id; identityResourceDto.Created = identityResource.Created; identityResourceDto.Updated = identityResource.Updated; identityResourceDto.Enabled = identityResource.Enabled; identityResourceDto.Name = identityResource.Name; identityResourceDto.DisplayName = identityResource.DisplayName; identityResourceDto.Required = identityResource.Required; identityResourceDto.Emphasize = identityResource.Emphasize; identityResourceDto.ShowInDiscoveryDocument = identityResource.ShowInDiscoveryDocument; identityResourceDto.NonEditable = identityResource.NonEditable; List <IdentityResourceClaimDto> identityResourceClaimDtos = new List <IdentityResourceClaimDto>(); foreach (var item in identityResource.UserClaims) { identityResourceClaimDtos.Add(new IdentityResourceClaimDto { Id = item.Id, Type = item.Type, IdentityResourceId = item.IdentityResourceId }); } identityResourceDto.UserClaims = identityResourceClaimDtos; List <IdentityResourcePropertyDto> identityResourcePropertyDtos = new List <IdentityResourcePropertyDto>(); foreach (var item in identityResource.Properties) { identityResourcePropertyDtos.Add(new IdentityResourcePropertyDto { Id = item.Id, Key = item.Key, Value = item.Value, IdentityResourceId = item.IdentityResourceId }); } identityResourceDto.Properties = identityResourcePropertyDtos; resultStatus.code = ResultCode.Success; result.custom = identityResourceDto; result.status = resultStatus; return(result); }
public static IdentityResource ToEntity(this IdentityResourceDto identityResourceDto, IdentityResource identityResource = null) { return(identityResourceDto == null ? null : Mapper.Map <IdentityResourceDto, IdentityResource>(identityResourceDto, identityResource)); }
public IdentityResourceUpdatedEvent(IdentityResourceDto originalIdentityResource, IdentityResourceDto identityResource) { OriginalIdentityResource = originalIdentityResource; IdentityResource = identityResource; }
public IActionResult GetIdentityResource(int?id) { IdentityResourceDto data = this.service.GetIdentityResourceDto(id); return(Success(data)); }
public IActionResult AddIdentityResource([FromBody] IdentityResourceDto identityResourceDto) { this.service.AddIdentityResource(identityResourceDto); return(Success()); }
public async Task <bool> CanInsertIdentityResourceAsync(IdentityResourceDto identityResource) { var resource = identityResource.ToEntity(); return(await _identityResourceRepository.CanInsertIdentityResourceAsync(resource)); }
public async Task <ApiResponse> UpdateIdentityResourceAsync([FromBody] IdentityResourceDto identityResourceDto) => await _adminManager.UpdateIdentityResourceAsync(identityResourceDto);