public IActionResult Add(int id) { var viewmodel = new ApiResourceSecretAddViewModel { ApiResourceId = id, Type = "SharedSecret" }; return(View(viewmodel)); }
public async Task <IActionResult> Add(ApiResourceSecretAddViewModel viewmodel) { if (ModelState.IsValid) { var record = _mapper.Map <ApiResourceSecret>(viewmodel); record.Value = new IdentityServer4.Models.Secret(viewmodel.NewSecret.ToSha256()).Value; record.Created = DateTime.UtcNow; _dbContext.ApiResourceSecrets.Add(record); var result = await _dbContext.SaveChangesAsync().ConfigureAwait(false); if (result > 0) { return(RedirectToAction("Details", "ApiResources", new { id = viewmodel.ApiResourceId })); } ModelState.AddModelError("", "Failed"); } return(View(viewmodel)); }