public string GetFullDepartmentName(int?id) { string departmentFullName = ""; while (true) { v_CurrentTreeOrg org = db.v_CurrentTreeOrg.Where(a => a.ID == id).FirstOrDefault(); if (org.SED_NAME == "") { departmentFullName = org.LONG_NAME + departmentFullName; } else { departmentFullName = org.SED_NAME + departmentFullName; } id = org.PID; if (id == null) { return(departmentFullName); } else { departmentFullName = " - " + departmentFullName; } } }
public TreeSearchResultDTO getSearchTree(string searchString) { IEnumerable <v_CurrentTreeOrg> allItems = db.v_CurrentTreeOrg.OrderBy(a => a.LONG_NAME).ToList(); searchString = searchString.ToLower(); searchString = searchString.Trim(); searchString = string.Join(" ", searchString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); IEnumerable <v_CurrentTreeOrg> searchItems = allItems.Where(s => ((s.SED_NAME.ToString().ToLower().Contains(searchString)) || (s.LONG_NAME.ToString().ToLower().Contains(searchString)))).ToList(); List <int?> searchItemsId = new List <int?>(); List <int?> treeItems = new List <int?>(); List <string> parentItemsId = new List <string>(); foreach (v_CurrentTreeOrg i in searchItems) { v_CurrentTreeOrg currentItem = i; searchItemsId.Add(currentItem.ID); while (currentItem.PID != null) { treeItems.Add(currentItem.ID); var parentId = currentItem.PID; currentItem = allItems.Where(a => a.ID == parentId).FirstOrDefault(); parentItemsId.Add(currentItem.ID.ToString()); } treeItems.Add(currentItem.ID); } var jsonString = "["; int?pID = null; jsonString = jsonString + getSearchTreeChildren(pID, allItems, treeItems, searchItemsId); jsonString = jsonString + "]"; TreeSearchResultDTO result = new TreeSearchResultDTO(); result.Tree = JsonConvert.DeserializeObject(jsonString); result.OpenNodes = parentItemsId; return(result); }
public TreeSearchResultDTO getSearchTree(string searchString, bool di, Guid?hi, Guid?user, Guid?approves, Guid?admins, Guid?exceptions, int?department) { IEnumerable <MailingGroup> allItems = new List <MailingGroup>(); if (searchString == null) { searchString = ""; } ; if (di) { allItems = db.MailingGroups.OrderBy(a => a.Name).ToList(); } else { allItems = db.MailingGroups.Where(a => a.Deleted == false).OrderBy(a => a.Name).ToList(); } searchString = searchString.ToLower(); searchString = searchString.Trim(); searchString = string.Join(" ", searchString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); searchString = searchString.Replace("ё", "е"); IEnumerable <MailingGroup> searchItems = allItems.Where(s => ((s.Name.ToString().ToLower().Contains(searchString)) || (s.Description.ToString().ToLower().Contains(searchString)))).ToList(); if (user != null) { searchItems = searchPeople(searchItems, user, 1); } if (approves != null) { searchItems = searchPeople(searchItems, approves, 2); } if (admins != null) { searchItems = searchPeople(searchItems, admins, 3); } if (exceptions != null) { searchItems = searchPeople(searchItems, exceptions, 4); } if (department != null) { List <MailingGroup> searchItemsList = new List <MailingGroup>(); MailingGroup item = new MailingGroup(); while (department != null) { var departmentStr = department.ToString(); IEnumerable <Unit> units = db.Units.Where(a => a.UnitEmployeeDbId == departmentStr).Where(a => a.Deleted == false).ToList(); if (units.Count() > 0) { foreach (Unit u in units) { item = searchItems.Where(a => a.Id == u.MailingGroupId).FirstOrDefault(); if (item != null) { searchItemsList.Add(item); } } } v_CurrentTreeOrg parent = EmployeeDB.v_CurrentTreeOrg.Where(a => a.ID == department).FirstOrDefault(); department = parent.PID; } searchItems = searchItemsList; } List <Guid> searchItemsId = new List <Guid>(); List <Guid> treeItems = new List <Guid>(); List <string> parentItemsId = new List <string>(); foreach (MailingGroup i in searchItems) { MailingGroup currentItem = i; searchItemsId.Add(currentItem.Id); while (currentItem.ParentId != null) { treeItems.Add(currentItem.Id); var parentId = currentItem.ParentId; currentItem = allItems.Where(a => a.Id == parentId).FirstOrDefault(); parentItemsId.Add(currentItem.Id.ToString()); } treeItems.Add(currentItem.Id); } var jsonString = "["; Guid?pID = null; jsonString = jsonString + getSearchTreeChildren(pID, allItems, treeItems, searchItemsId, di, hi); jsonString = jsonString + "]"; TreeSearchResultDTO result = new TreeSearchResultDTO(); result.Tree = JsonConvert.DeserializeObject(jsonString); result.OpenNodes = parentItemsId; return(result); }