private void addWorkGroupUsers(List <Data.Model.Users> userList, Data.Model.WorkGroup wg) { if (wg == null || wg.Members.IsNullOrEmpty()) { return; } string[] idArray = wg.Members.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); Users busers = new Users(); WorkGroup bwg = new WorkGroup(); foreach (var id in idArray) { if (id.StartsWith(Users.PREFIX))//人员 { userList.Add(busers.Get(Users.RemovePrefix(id).ToGuid())); } else if (id.IsGuid())//机构 { userList.AddRange(GetAllUsers(id.ToGuid())); } else if (id.StartsWith(WorkGroup.PREFIX))//工作组 { addWorkGroupUsers(userList, bwg.Get(WorkGroup.RemovePrefix(id).ToGuid())); } } }
/// <summary> /// 得到一组机构字符串下所有人员 /// </summary> /// <param name="idString"></param> /// <returns></returns> public List <Data.Model.Users> GetAllUsers(string idString) { if (idString.IsNullOrEmpty()) { return(new List <Data.Model.Users>()); } string[] idArray = idString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); List <Data.Model.Users> userList = new List <Data.Model.Users>(); Users busers = new Users(); WorkGroup bwg = new WorkGroup(); foreach (string id in idArray) { if (id.StartsWith(Users.PREFIX))//人员 { userList.Add(busers.Get(Users.RemovePrefix(id).ToGuid())); } else if (id.IsGuid())//机构 { userList.AddRange(GetAllUsers(id.ToGuid())); } else if (id.StartsWith(WorkGroup.PREFIX))//工作组 { addWorkGroupUsers(userList, bwg.Get(WorkGroup.RemovePrefix(id).ToGuid())); } } userList.RemoveAll(p => p == null); return(userList); }
/// <summary> /// 根据ID得到名称(有前缀的情况) /// </summary> /// <param name="id"></param> /// <returns></returns> public string GetName(string id) { string name = string.Empty; if (id.IsGuid())//机构 { return(GetName(id.ToGuid())); } else if (id.StartsWith(Users.PREFIX))//用户 { string uid = Users.RemovePrefix(id); Guid userID; if (!uid.IsGuid(out userID)) { return(""); } else { return(new Users().GetName(userID)); } } else if (id.StartsWith(WorkGroup.PREFIX))//工作组 { string uid = WorkGroup.RemovePrefix(id); Guid wid; if (!uid.IsGuid(out wid)) { return(""); } else { return(new WorkGroup().GetName(wid)); } } return(""); }