/// <summary>
        /// 取得某一個群組的搜索網站Resource權限權限對應
        /// </summary>
        /// <param name="roleName">群組名稱</param>
        /// <param name="roleId">群組Id</param>
        /// <param name="resourceOperation">網站全部的資源對應</param>
        /// <returns>修改ViewModel</returns>
        public Edit GetCurrentRolePermission(string roleName, string roleId,
            List<ResourceOperation> resourceOperation)
        {
            var currentRolePermission = GetResourceOperationForRole(roleId);

            foreach (var item in resourceOperation)
            {
                var rolePermission = currentRolePermission.Where(x => x.ResourceName == item.ResourceName).FirstOrDefault();

                if (rolePermission != null)
                {
                    item.Operation = rolePermission.Operation;
                }
                else
                {
                    // 表示沒有權限
                    item.Operation = ResourceOperationEnum.None;
                }
            }

            var viewModel = new Edit()
            {
                ResourceOperation = resourceOperation,
                RoleName = roleName,
                RoleId = roleId
            };

            return viewModel;
        }
        /// <summary>
        /// 更新ViewModel設定的權限到DB
        /// </summary>
        /// <param name="viewModel">設定的權限</param>
        public void SaveCurrentRolePermission(Edit viewModel)
        {
            var currentPermission = GetRolesPermissionForRole(viewModel.RoleId);

            SaveRolePermissionToTable(viewModel.RoleId, viewModel.ResourceOperation, currentPermission);
        }
        public async Task<ActionResult> Edit(Edit viewModel)
        {
            if (ModelState.IsValid)
            {
                var role = await RoleManager.FindByIdAsync(viewModel.RoleId);
                role.Name = viewModel.RoleName;
                await RoleManager.UpdateAsync(role);

                ResourceOperationPermission rop = new ResourceOperationPermission();

                rop.SaveCurrentRolePermission(viewModel);

                return RedirectToAction("Index").WithSuccess("修改群組成功");
            }
            return View();
        }