예제 #1
0
        public async Task <IActionResult> EditRole(string id)
        {
            var role = await _roleManager.FindByIdAsync(id);

            if (role == null)
            {
                return(RedirectToAction("Index"));
            }

            var roleEditViewModel = new RoleEditViewModel
            {
                Id       = id,
                RoleName = role.Name,
                Users    = new List <string>()
            };
            List <string> userList = new List <string>();

            var re = SessionOps.GetSessionList <string>(HttpContext.Session.Get($"role_{id}_user_list"));

            if (re != null)
            {
                userList = re;
            }
            else
            {
                var configAuthorization = Config.App.GetJToken(Constants.JsontagAuthorization) as JObject;
                var authBlob            = AzureService.GetBlob(null, "index", WebUIConfig.AppInfoConfigFile);
                var json = await authBlob.DownloadGenericObjectAsync();

                var addAuth    = JsonUtils.GetJToken(Constants.JsontagAuthorization, json);
                var addAuthObj = addAuth == null ? null : addAuth as JObject;
                if (!Object.ReferenceEquals(addAuthObj, null))
                {
                    addAuthObj.Merge(configAuthorization, new JsonMergeSettings
                    {
                        MergeArrayHandling = MergeArrayHandling.Union
                    });
                }
                if (!Object.ReferenceEquals(addAuthObj, null))
                {
                    foreach (var pair in addAuthObj)
                    {
                        if (pair.Key == role.Name)
                        {
                            var peopleArray = pair.Value as JArray;
                            foreach (var onepeople in peopleArray)
                            {
                                userList.Add(onepeople.ToString());
                            }
                        }
                    }
                }
                SessionOps.SetSession($"role_{id}_user_list", userList, HttpContext.Session);
            }
            roleEditViewModel.Users = userList;
            return(View(roleEditViewModel));
        }
예제 #2
0
        public async Task <IActionResult> DeleteUserFromRole(string roleId)
        {
            var role = await _roleManager.FindByIdAsync(roleId);

            if (role == null)
            {
                return(RedirectToAction("Index"));
            }

            var vm = new UserRoleViewModel
            {
                RoleId = role.Id
            };

            List <string> userList = new List <string>();
            var           re       = SessionOps.GetSessionList <string>(HttpContext.Session.Get($"role_{roleId}_user_list"));

            if (re != null)
            {
                userList = re;
            }
            else
            {
                var authBlob = AzureService.GetBlob(null, "index", WebUIConfig.AppInfoConfigFile);
                var json     = await authBlob.DownloadGenericObjectAsync();

                var addAuth    = JsonUtils.GetJToken(Constants.JsontagAuthorization, json);
                var addAuthObj = addAuth == null ? null : addAuth as JObject;

                if (!Object.ReferenceEquals(addAuthObj, null))
                {
                    foreach (var pair in addAuthObj)
                    {
                        if (pair.Key == role.Name)
                        {
                            var peopleArray = pair.Value as JArray;
                            foreach (var onepeople in peopleArray)
                            {
                                userList.Add(onepeople.ToString());
                            }
                        }
                    }
                }
                SessionOps.SetSession($"role_{roleId}_user_list", userList, HttpContext.Session);
            }
            vm.Users = userList;
            return(View(vm));
        }