public async Task <IActionResult> Edit(ApiSecretViewModel vm) { if (vm == null) { return(BadRequest()); } if (ModelState.IsValid) { var obj = await _dbContext.Set <ApiSecret>().FindAsync(vm.Id); if (obj == null) { return(NotFound()); } obj.Type = vm.Type; obj.Description = vm.Description; obj.Expiration = vm.Expiration; try { await _dbContext.SaveChangesAsync(); _logger.LogInformation($"API secret Id {obj.Id} updated by {User?.Identity?.Name}."); return(RedirectToAction("Edit", "ApiResources", new { id = vm.ApiResourceId })); } catch (DbException ex) { _logger.LogError(ex.GetBaseException()?.Message ?? ex.Message); throw; } } return(View(vm)); }
public async Task <IActionResult> Delete(ApiSecretViewModel vm) { if (vm == null) { return(BadRequest()); } var obj = await _dbContext.Set <ApiSecret>().FindAsync(vm.Id); if (obj == null) { return(NotFound()); } _dbContext.Remove(obj); try { await _dbContext.SaveChangesAsync(); _logger.LogInformation($"API secret Id {obj.Id} removed by {User?.Identity?.Name}."); return(RedirectToAction("Edit", "ApiResources", new { id = vm.ApiResourceId })); } catch (DbException ex) { _logger.LogError(ex.GetBaseException()?.Message ?? ex.Message); throw; } }