public IActionResult SaveScope(ScopeInputViewModel model, [FromQuery] string parent = null)
        {
            switch (model.ScopeType)
            {
            case ScopeType.Identity:
                _context.IdentityResources.Add(new IdentityResource
                {
                    DisplayName = model.ScopeName,
                    Name        = model.ScopeName,
                    Enabled     = true
                });
                break;

            case ScopeType.ApiResource:
                _context.ApiResources.Add(new ApiResource
                {
                    Name        = model.ScopeName,
                    DisplayName = model.ScopeName,
                    Enabled     = true
                });
                break;

            case ScopeType.Api:
                if (parent == null)
                {
                    return(RedirectToAction(nameof(ManageScopes), new { message = $"Parent scope must be specified" }));
                }

                var api = _context.ApiResources.Include(x => x.Scopes)
                          .SingleOrDefault(x => x.Name == parent);

                if (api == null)
                {
                    return(RedirectToAction(nameof(ManageScopes), new { message = $"Could not find api {parent}" }));
                }

                if (api.Scopes.Any(x => x.Name == model.ScopeName))
                {
                    return(RedirectToAction(nameof(ManageScopes), new { message = $"Duplicate scope {model.ScopeName} found for {parent}" }));
                }

                api.Scopes.Add(new ApiScope
                {
                    Name        = model.ScopeName,
                    DisplayName = model.ScopeName
                });

                break;
            }
            _context.SaveChanges();
            return(RedirectToAction(nameof(ManageScopes), new { message = $"New {model.ScopeType} Scope {model.ScopeName} Created" }));
        }
Пример #2
0
        public void StoreElement(XElement element, string friendlyName)
        {
            var entity = _context.DataProtectionKeys.SingleOrDefault(k => k.FriendlyName == friendlyName);

            if (null != entity)
            {
                entity.XmlData = element.ToString();
                _context.DataProtectionKeys.Update(entity);
            }
            else
            {
                _context.DataProtectionKeys.Add(new DataProtectionKey
                {
                    FriendlyName = friendlyName,
                    XmlData      = element.ToString()
                });
            }

            _context.SaveChanges();
        }