public async Task <bool> AddSecret(CreateApiSecretDto apiSecret) { var apiresource = await _apiresourceRepository.GetByIdAsync(apiSecret.ApiResourceId); if (apiresource == null) { throw new Exception("apiResource不存在"); } var entity = _mapper.Map <ApiSecret>(apiSecret); if (apiSecret.Hash == HashType.Sha256) { entity.Value = apiSecret.Value.Sha256(); } else if (apiSecret.Hash == HashType.Sha512) { entity.Value = apiSecret.Value.Sha512(); } await _apisecretRepository.AddAsync(entity); return(await _apisecretRepository.SaveChangesAsync() > 0); }
public async Task <IActionResult> AddApiSecret(CreateApiSecretDto apiSecret) { if (!ModelState.IsValid) { return(BadRequest(ModelStateErrors)); } var result = await _apiresourceService.AddSecret(apiSecret); return(ResultResponse(result, "添加ApiSecret成功")); }