private void RebuildFolderTreeView(List <SecureItemViewModel> items) { var oldTree = allHierarchyFolderList; allHierarchyFolderList = new List <FolderView>(); foreach (var item in pbData.GetFoldersBySecureItemType()) { var previosFolderState = FindTreeView(oldTree, item.Id); allHierarchyFolderList.Add(new FolderView(item.Id, item.ParentId, item.Name, previosFolderState == null ? true : previosFolderState.IsExpanded)); } var previosRootFolderState = oldTree.FirstOrDefault(x => x.uuid == string.Empty); var rootFolder = new FolderView(string.Empty, string.Empty, "No Folder", previosRootFolderState == null ? true : previosRootFolderState.IsExpanded); allHierarchyFolderList.Add(rootFolder); foreach (var item in SortSecureItems(items)) { if (item.Folder != null) { var folder = allHierarchyFolderList.FirstOrDefault(x => x.uuid == item.Folder.Id); if (folder != null) { folder.AddSecureItem(item); continue; } } rootFolder.AddSecureItem(item); } var itemsToRemove = new List <FolderView>(); for (int i = 0; i < allHierarchyFolderList.Count; i++) { if (!string.IsNullOrEmpty(allHierarchyFolderList[i].parentId)) { var parent = allHierarchyFolderList.FirstOrDefault(x => x.uuid == allHierarchyFolderList[i].parentId); if (parent != null && parent.uuid != allHierarchyFolderList[i].uuid) { parent.ChildList.Add(allHierarchyFolderList[i]); itemsToRemove.Add(allHierarchyFolderList[i]); } } } foreach (var item in itemsToRemove) { allHierarchyFolderList.Remove(item); } }
public void MoveSecureItemToFolder(IEnumerable <object> items, string folderId) { if (items == null) { return; } var folder = pbData.GetFolderById(folderId); var temp = new List <object>(items); bool IsSearch; if (folder != null) { foreach (var it in temp) { var item = it as SecureItemViewModel; if (item != null) { var secureItemVM = GetFullSecureItem(item.Id); if (secureItemVM != null) { item = secureItemVM; } FolderView oldFolder = null; if (item.Folder != null) { oldFolder = FindTreeViewWithDefault(allHierarchyFolderList, item.Folder.Id); } FolderView folderView = FindTreeViewWithDefault(allHierarchyFolderList, folderId); item.Folder = folder; if (SaveItem(item.CreateSecureItem())) { if (oldFolder != null) { oldFolder.RemoveSecureItem(item); } if (folderView != null) { folderView.AddSecureItem(item); } } } } // RefreshData(); // folderView.IsExpanded = true; } }
private void RebuildByTypeTreeView(List <ISecureItemVM> items) { allHierarchyTypeList = new List <FolderView>(); foreach (var type in items.GroupBy(x => x.SubType)) { var typeView = new FolderView() { FolderName = type.Key, IsExpanded = true }; foreach (var item in type) { typeView.AddSecureItem(item); } allHierarchyTypeList.Add(typeView); } }