public static async Task <RolePriority> GetMaxPriority(User u) { UserServiceProxy usrv = new UserServiceProxy(); var l = await usrv.MaterializeAllUsersInRole_UserIDsAsync(Cntx, u); if (l == null || l.Count() == 0) { return new RolePriority { Major = -1, Minor = -1 } } ; UsersInRoleServiceProxy uisvc = new UsersInRoleServiceProxy(); foreach (var ir in l) { ir.RoleRef = uisvc.MaterializeRoleRef(Cntx, ir); } var uir = (from d in l orderby d.RoleRef.RolePriority descending, d.SubPriority descending select d).First(); var roleids = (from d in l orderby d.RoleRef.RolePriority select d.RoleID).ToArray(); return(new RolePriority { Major = uir.RoleRef.RolePriority, Minor = uir.SubPriority, RoleIds = roleids, MaxRole = uir.RoleRef }); }
public static async Task<RolePriority> GetMaxPriority(User u) { UserServiceProxy usrv = new UserServiceProxy(); var l = await usrv.MaterializeAllUsersInRole_UserIDsAsync(Cntx, u); if (l == null || l.Count() == 0) return new RolePriority { Major = -1, Minor = -1 }; UsersInRoleServiceProxy uisvc = new UsersInRoleServiceProxy(); foreach (var ir in l) ir.RoleRef = uisvc.MaterializeRoleRef(Cntx, ir); var uir = (from d in l orderby d.RoleRef.RolePriority descending, d.SubPriority descending select d).First(); var roleids = (from d in l orderby d.RoleRef.RolePriority select d.RoleID).ToArray(); return new RolePriority { Major = uir.RoleRef.RolePriority, Minor = uir.SubPriority, RoleIds = roleids, MaxRole = uir.RoleRef }; }
public static async Task<string> GetManagedUsers(string adminId, string set, string qexpr, string prevlast) { var maxp = await GetMaxPriority(adminId); JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; EntitySetType type; if (Enum.TryParse<EntitySetType>(sobj["set"], out type)) { switch (type) { case EntitySetType.User: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(User)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; UserServiceProxy svc = new UserServiceProxy(); UserSet _set = new UserSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) _set.SetFilter = sobj["setFilter"]; User _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as User; } RoleServiceProxy rsvc = new RoleServiceProxy(); var roles = await rsvc.QueryDatabaseAsync(Cntx, new RoleSet(), null); var result = await svc.GetPageItemsAsync(Cntx, _set, _qexpr, _prevlast); var ar = new List<dynamic>(); string appId = ApplicationContext.App.ID; UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy(); foreach (var e in result) { List<Role> rlist = new List<Role>(); foreach (var r in roles) { if (r.RolePriority <= maxp.Major) rlist.Add(r); } var p = await GetMaxPriority(e); List<dynamic> rolelist = new List<dynamic>(); var _roles = await svc.MaterializeAllUsersInRole_UserIDsAsync(Cntx, e); dynamic _max = null; if (_roles != null) { List<UsersInRole> _rlist = new List<UsersInRole>(); foreach (var ir in _roles) { ir.RoleRef = uirsvc.MaterializeRoleRef(Cntx, ir); _rlist.Add(ir); } foreach (var ir in from d in _rlist orderby d.RoleRef.RolePriority descending, d.SubPriority descending select d) { bool op = adminId != e.ID && (ir.RoleRef.RolePriority < maxp.Major || ir.RoleRef.RolePriority == maxp.Major && ir.SubPriority <= maxp.Minor); var _r = new { id = ir.RoleRef.ID, uid = ir.UserID, name = ir.RoleRef.RoleName, path = Utils.GetHtmlRolePath(ir.RoleRef.DistinctString), level = ir.SubPriority, op = op }; if (ir.RoleRef.ID == p.MaxRole.ID) _max = _r; rolelist.Add(_r); int ptr = -1; for (int i = 0; i < rlist.Count; i++) { if (rlist[i].ID == ir.RoleRef.ID) { ptr = i; break; } } if (ptr != -1) rlist.RemoveAt(ptr); } } List<dynamic> availablers = new List<dynamic>(); //if (adminId != e.ID) { foreach (var r in rlist) availablers.Add(new { id = r.ID, name = r.RoleName, path = Utils.GetHtmlRolePath(r.DistinctString), op = true }); } var membs = svc.MaterializeAllUserAppMembers(Cntx, e); ar.Add(new { data = e, member = (from d in membs where d.ApplicationID == appId select d).SingleOrDefault(), roles = rolelist.ToArray(), maxrole = _max, availableRoles = availablers.ToArray(), CanEdit = p.IsLowerOrEqual(maxp) }); } string json = ser3.Serialize(ar); return json; } } } return null; }
public static async Task <string> GetManagedUsers(string adminId, string set, string qexpr, string prevlast) { var maxp = await GetMaxPriority(adminId); JavaScriptSerializer jser = new JavaScriptSerializer(); dynamic sobj = jser.DeserializeObject(set) as dynamic; EntitySetType type; if (Enum.TryParse <EntitySetType>(sobj["set"], out type)) { switch (type) { case EntitySetType.User: { DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(QueryExpresion)); DataContractJsonSerializer ser2 = new DataContractJsonSerializer(typeof(User)); var ser3 = new JavaScriptSerializer(); System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] sbf = System.Text.Encoding.UTF8.GetBytes(qexpr); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; var _qexpr = ser1.ReadObject(strm) as QueryExpresion; UserServiceProxy svc = new UserServiceProxy(); UserSet _set = new UserSet(); _set.PageBlockSize = int.Parse(sobj["pageBlockSize"]); _set.PageSize_ = int.Parse(sobj["pageSize"]); if (sobj.ContainsKey("setFilter")) { _set.SetFilter = sobj["setFilter"]; } User _prevlast = null; if (!string.IsNullOrEmpty(prevlast)) { strm = new System.IO.MemoryStream(); sbf = System.Text.Encoding.UTF8.GetBytes(prevlast); strm.Write(sbf, 0, sbf.Length); strm.Position = 0; _prevlast = ser2.ReadObject(strm) as User; } RoleServiceProxy rsvc = new RoleServiceProxy(); var roles = await rsvc.QueryDatabaseAsync(Cntx, new RoleSet(), null); var result = await svc.GetPageItemsAsync(Cntx, _set, _qexpr, _prevlast); var ar = new List <dynamic>(); string appId = ApplicationContext.App.ID; UsersInRoleServiceProxy uirsvc = new UsersInRoleServiceProxy(); foreach (var e in result) { List <Role> rlist = new List <Role>(); foreach (var r in roles) { if (r.RolePriority <= maxp.Major) { rlist.Add(r); } } var p = await GetMaxPriority(e); List <dynamic> rolelist = new List <dynamic>(); var _roles = await svc.MaterializeAllUsersInRole_UserIDsAsync(Cntx, e); dynamic _max = null; if (_roles != null) { List <UsersInRole> _rlist = new List <UsersInRole>(); foreach (var ir in _roles) { ir.RoleRef = uirsvc.MaterializeRoleRef(Cntx, ir); _rlist.Add(ir); } foreach (var ir in from d in _rlist orderby d.RoleRef.RolePriority descending, d.SubPriority descending select d) { bool op = adminId != e.ID && (ir.RoleRef.RolePriority < maxp.Major || ir.RoleRef.RolePriority == maxp.Major && ir.SubPriority <= maxp.Minor); var _r = new { id = ir.RoleRef.ID, uid = ir.UserID, name = ir.RoleRef.RoleName, path = Utils.GetHtmlRolePath(ir.RoleRef.DistinctString), level = ir.SubPriority, op = op }; if (ir.RoleRef.ID == p.MaxRole.ID) { _max = _r; } rolelist.Add(_r); int ptr = -1; for (int i = 0; i < rlist.Count; i++) { if (rlist[i].ID == ir.RoleRef.ID) { ptr = i; break; } } if (ptr != -1) { rlist.RemoveAt(ptr); } } } List <dynamic> availablers = new List <dynamic>(); //if (adminId != e.ID) { foreach (var r in rlist) { availablers.Add(new { id = r.ID, name = r.RoleName, path = Utils.GetHtmlRolePath(r.DistinctString), op = true }); } } var membs = svc.MaterializeAllUserAppMembers(Cntx, e); ar.Add(new { data = e, member = (from d in membs where d.ApplicationID == appId select d).SingleOrDefault(), roles = rolelist.ToArray(), maxrole = _max, availableRoles = availablers.ToArray(), CanEdit = p.IsLowerOrEqual(maxp) }); } string json = ser3.Serialize(ar); return(json); } } } return(null); }