public async Task <ActionResult> Scopes(UserScopeModel model)
        {
            var fullUserStore = UserManager.FullUserStore;
            var adminStore    = new IdentityServer3AdminStore();

            if (model.UserScopeRecords != null)
            {
                // remove the ones that need to be removed
                var queryToBeDeleted = (from item in model.UserScopeRecords
                                        where item.Enabled == false
                                        select item.Name).ToList();
                await adminStore.DeleteScopesByUserIdAsync(model.UserId, queryToBeDeleted);
            }

            var queryToBeAdded = (from item in model.AllowedScopes
                                  where item.Enabled
                                  select item.Name).ToList();

            // add the ones that need to be added.
            if (queryToBeAdded.Any())
            {
                await adminStore.AddScopesToIdentityServerUserAsync(model.UserId, queryToBeAdded);
            }

            return(RedirectToAction("Index"));
        }
        // GET: Admin/Home/Manage/5
        public async Task <ActionResult> Scopes(string id, string email)
        {
            // note this is POC.  We need a dynamic ajax page that does paging
            var usm = new UserScopeModel
            {
                AllowedScopes    = new List <UserScopeRecord>(),
                UserScopeRecords = new List <UserScopeRecord>(),
                Email            = email,
                UserId           = id
            };

            var fullUserStore = UserManager.FullUserStore;
            var adminStore    = new IdentityServer3AdminStore();
            var userScopes    = await adminStore.FindScopesByUserAsync(id);

            foreach (var scope in userScopes)
            {
                usm.UserScopeRecords.Add(new UserScopeRecord()
                {
                    Enabled = true, Name = scope
                });
            }
            int pageSize = 100;
            var page     = await adminStore.PageScopesAsync(100, null);

            var state  = HttpUtility.UrlEncode(page.PagingState);
            var record = new IDSScopePageRecord()
            {
                CurrentPagingState = HttpUtility.UrlEncode(page.CurrentPagingState),
                PageSize           = pageSize,
                PagingState        = HttpUtility.UrlEncode(page.PagingState),
                Scopes             = page
            };

            foreach (var scope in page)
            {
                usm.AllowedScopes.Add(new UserScopeRecord()
                {
                    Enabled = false,
                    Name    = scope.Name
                });
            }
            return(View(usm));
        }