public static async Task GetRootItems(FolderTreeViewModel folderTree) { Debug.Assert(folderTree != null); var db = Database.DbConnection; var rootFolders = await db.Table <Folders>().Where(f => f.Parent == 0).ToListAsync(); // Skip single rootfolders, unless it does not have children while (rootFolders.Count == 1) { var rootId = rootFolders.First().Id; var children = await db.Table <Folders>().Where(f => f.Parent == rootId).ToListAsync(); if (children.Count == 0) { break; } rootFolders = children; } var root = new ObservableCollection <FolderViewModel>(); foreach (Folders folder in rootFolders) { var folderViewModel = new FolderViewModel(folder, null, folderTree); await folderViewModel.ReadChildrenFromDb(); root.Add(folderViewModel); } folderTree.Children = root; }
//private async Task<List<int>> GetIdTree() //{ // } #endregion #region ReadChildren private async Task ReadChildrenFromDb() { var db = Database.DbConnection; var children = await db.Table <Folders>().Where(f => f.Parent == this._folder.Id).ToListAsync(); foreach (Folders childfolder in children) { var child = new FolderViewModel(childfolder, this, _visualTree); _children.Add(child); await child.ReadChildrenFromDb(); } }