public async Task <IActionResult> EditApiScope(int id) { var apiScope = await _configurationDbContext .ApiScopes .Where(q => q.Id == id) .Include(q => q.UserClaims) .AsNoTracking() .FirstOrDefaultAsync(); if (apiScope == null) { ModelState.AddModelError(string.Empty, "ApiScope未找到."); var apiScopes = await _configurationDbContext .ApiScopes .AsNoTracking() .ToListAsync(); return(View("Index", apiScopes)); } var vm = new ApiScopeEditViewModel { Id = id, Enabled = apiScope.Enabled, Name = apiScope.Name, DisplayName = apiScope.DisplayName, Description = apiScope.Description, ApiScopeClaims = new List <string>() }; if (!apiScope.UserClaims.IsNullOrEmpty()) { foreach (var scope in apiScope.UserClaims) { vm.ApiScopeClaims.Add(scope.Type); } } return(View(vm)); }
public async Task <IActionResult> EditApiScope(ApiScopeEditViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var apiScope = await _configurationDbContext .ApiScopes .FirstOrDefaultAsync(q => q.Id == model.Id); apiScope.Enabled = model.Enabled; apiScope.Name = model.Name; apiScope.Description = model.Description; apiScope.DisplayName = model.DisplayName; _configurationDbContext.Update(apiScope); await _configurationDbContext.SaveChangesAsync(); return(RedirectToAction("Index")); }