public IActionResult Create(int clientId) { var vm = new ClientSecretInputViewModel { ClientId = clientId, Expiration = DateTime.Today.AddYears(1) }; return(View(vm)); }
public async Task <IActionResult> Create(ClientSecretInputViewModel vm) { if (vm == null) { return(BadRequest()); } if (ModelState.IsValid) { var client = await _dbContext.Clients.FindAsync(vm.ClientId); if (client == null) { return(BadRequest()); } var clientSecret = new ClientSecret { Client = client, Description = vm.Description, Value = vm.Value.Sha256(), Expiration = vm.Expiration }; if (!string.IsNullOrEmpty(vm.Type)) { clientSecret.Type = vm.Type; } _dbContext.Set <ClientSecret>().Add(clientSecret); try { await _dbContext.SaveChangesAsync(); _logger.LogInformation($"Client secret Id {clientSecret.Id} created by {User?.Identity?.Name}."); return(RedirectToAction("Edit", "Clients", new { id = vm.ClientId })); } catch (DbException ex) { _logger.LogError(ex.GetBaseException()?.Message ?? ex.Message); throw; } } return(View(vm)); }