Пример #1
0
        /// <summary>
        /// 更改IdentityResource的内容,包括name, displayName, ClaimType
        /// </summary>
        /// <param name="id">IdentityResource Id</param>
        /// <returns></returns>
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }
            var identityResource = await _configurationContext.IdentityResources.Include(a => a.UserClaims).Where(a => a.Id == id).FirstOrDefaultAsync();

            if (identityResource != null)
            {
                var identityResourceModel = identityResource.ToModel();
                var viewModel             = new IdentityResourcesEditViewModel
                {
                    Id          = identityResource.Id,
                    Name        = identityResourceModel.Name,
                    DisplayName = identityResourceModel.DisplayName,
                    ClaimTypes  = identityResourceModel.UserClaims.ToList()
                };
                return(View(viewModel));
            }
            else
            {
                return(BadRequest());
            }
        }
Пример #2
0
        public async Task <IActionResult> Edit(IdentityResourcesEditViewModel identityResourcesEditViewModel)
        {
            if (ModelState.IsValid)
            {
                var identityResource = await EditIdentityResource(identityResourcesEditViewModel.Id, identityResourcesEditViewModel.Name, identityResourcesEditViewModel.DisplayName, identityResourcesEditViewModel.Emphasize, identityResourcesEditViewModel.ClaimTypes);

                if (identityResource != null)
                {
                    var identityResourceSelect = new List <SelectListItem>();

                    if (_cache.TryGetValue(CacheKeys.IdentityResourceDisplayNameSelectEntry, out identityResourceSelect))
                    {
                        _cache.Remove(CacheKeys.IdentityResourceDisplayNameSelectEntry);
                    }

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    ModelState.AddModelError(String.Empty, "更新失败!请注意输入项是否完整!");
                }
            }
            return(View(identityResourcesEditViewModel));
        }