private void LoadAuthorisationPermissions(SafeUserModel userModel) { userModel.PermissionGroups = new ObservableCollection <PermissionGroupModel>(); var userPermissions = userModel.User.UserPermissions.Select(x => x.Permission); foreach (var permissionGroup in PermissionGroups) { var premissionGroupModel = new PermissionGroupModel(permissionGroup); premissionGroupModel.Permissions = new ObservableCollection <PermissionModel>(); foreach (Permission permission in permissionGroup.Permissions.OrderBy(x => x.Name)) { var permissionModel = new PermissionModel(permission) { IsChecked = userPermissions.Contains(permission) }; permissionModel.PropertyChanged += PermissionModelOnPropertyChanged; permissionModel.Permission.PropertyChanged += OnPropertyChanged; premissionGroupModel.Permissions.Add(permissionModel); } premissionGroupModel.IsChecked = premissionGroupModel.Permissions.Any() && premissionGroupModel.Permissions.All((x) => x.IsChecked); premissionGroupModel.PropertyChanged += PremissionGroupModelOnPropertyChanged; premissionGroupModel.PermissionGroup.PropertyChanged += OnPropertyChanged; userModel.PermissionGroups.Add(premissionGroupModel); } }
public async Task OnGetAsync(string id) { var role = await _roleManager.FindByIdAsync(id); var claims = await _roleManager.GetClaimsAsync(role); var groups = _permissionDefinitionManager.GetGroups(); Groups = new List <PermissionGroupModel>(); foreach (var sys in groups) { foreach (var mod in sys.Permissions) { var group = new PermissionGroupModel { Name = mod.Name, DisplayName = mod.DisplayName }; group.Permissions = mod.Children.Select(p => new PermissionGrantModel { Name = p.Name, DisplayName = p.DisplayName, }).ToList(); Groups.Add(group); } } }
private void LoadAuthorisationPermissions(UserGroupModel groupModel) { groupModel.PermissionGroups = new ObservableCollection <PermissionGroupModel>(); var groupPermissions = groupModel.UserGroup.UserGroupPermissions.Select(x => x.Permission); foreach (var permissionGroup in PermissionGroups) { var premissionGroupModel = new PermissionGroupModel(permissionGroup); premissionGroupModel.Permissions = new ObservableCollection <PermissionModel>(); foreach (Permission permission in permissionGroup.Permissions) { var permissionModel = new PermissionModel(permission) { IsChecked = groupPermissions.Contains(permission) }; permissionModel.PropertyChanged += PermissionModelOnPropertyChanged; permissionModel.Permission.PropertyChanged += OnPropertyChanged; premissionGroupModel.Permissions.Add(permissionModel); } premissionGroupModel.IsChecked = premissionGroupModel.Permissions.Any() && premissionGroupModel.Permissions.All((x) => x.IsChecked); premissionGroupModel.PropertyChanged += PremissionGroupModelOnPropertyChanged; premissionGroupModel.PermissionGroup.PropertyChanged += PremissionGroupOnPropertyChanged; groupModel.PermissionGroups.Add(premissionGroupModel); groupModel.PropertyChanged += OnPropertyChanged; groupModel.UserGroup.PropertyChanged += OnPropertyChanged; } }
public PermissionModel() { PermissionGroup = new PermissionGroupModel(); }
public IList <PermissionGroupModel> GetListPermissionGroup(string group_code) { IList <PermissionGroupModel> resp = new List <PermissionGroupModel>(); try { using (MSSql mssql = new MSSql(DBConnectionType.RBAC, _EnvironmentModel)) { string used_id = ""; int seq = 0; string queryGroup = string.Format( @"SELECT C.code as group_code, C.name_thai as group_name, A.account_id, (A.prefixes + A.first_name + ' ' + A.last_name) as account_full_name, D.name_thai as account_department, (CASE WHEN C.code IS NULL THEN 0 ELSE 1 END) as used FROM [dbo].[SYS_ACCOUNT] A LEFT OUTER JOIN [dbo].[SYS_PERMISSION_GROUP] B ON A.account_id = B.account_id LEFT OUTER JOIN [dbo].[SYS_USER_GROUP] C ON B.group_code = C.code LEFT OUTER JOIN [dbo].[SYS_SECTION] D ON A.section_code = D.code WHERE C.code='{0}' ", group_code); var dtGroup = mssql.GetDataTableFromQueryStr(queryGroup); if (dtGroup.Rows.Count > 0) { foreach (DataRow dr in dtGroup.Rows) { PermissionGroupModel permiss = new PermissionGroupModel() { seq = seq, group_code = dr["group_code"].ToString(), group_name = dr["group_name"].ToString(), account_id = dr["account_id"].ToString(), account_full_name = dr["account_full_name"].ToString(), account_department = dr["account_department"].ToString(), used = Convert.ToBoolean(dr["used"]), }; used_id += string.Format(@"{0}{1}", dr["account_id"].ToString(), ","); seq += 1; resp.Add(permiss); } } string account_id_array = used_id.Replace(",", "','"); string queryUsers = string.Format( @"SELECT NULL as code, NULL as name_thai, A.account_id, (A.prefixes + A.first_name + ' ' + A.last_name) as account_full_name, B.name_thai as account_department, 0 as used FROM [dbo].[SYS_ACCOUNT] A INNER JOIN [dbo].[SYS_SECTION] B ON A.section_code = B.code WHERE 1=1 {0}", account_id_array.Length > 0 ? " AND A.account_id NOT IN ('" + account_id_array.Remove(account_id_array.Length - 3, 3) + "')" : ""); var dtUser = mssql.GetDataTableFromQueryStr(queryUsers); if (dtUser.Rows.Count > 0) { foreach (DataRow dr in dtUser.Rows) { PermissionGroupModel permiss = new PermissionGroupModel() { seq = seq, group_code = group_code, group_name = "", account_id = dr["account_id"].ToString(), account_full_name = dr["account_full_name"].ToString(), account_department = dr["account_department"].ToString(), used = Convert.ToBoolean(dr["used"]), }; seq += 1; resp.Add(permiss); } } return(resp); } } catch (Exception ex) { _ILogs.LogError("GetList PermissionGroup Repository: ", ex.Message.ToString(), ex.StackTrace); } return(null); }