public async Task LoadSites() { if (Sites != null) { Sites = null; } Sites = await DataBaseReader.ReturnSiteItems(Role); }
private void Sorting(Siteitem root) { foreach (Siteitem item in root.SubItems) { if (item.SubItems.Count > 0) { item.SubItems = new ObservableCollection <Siteitem>(item.SubItems.OrderBy(n => n.Title)); Sorting(item); } } }
public async Task <Siteitem> ReturnSiteItems(RoleItem role) { log.Debug("Getting SiteItems for {0}", role.Name); var db = new SQLiteConnection(mainDB); if (role == null) { return(new Siteitem()); } List <SiteDBPull> SiteCommandList = new List <SiteDBPull>(); SQLiteCommand pullall = new SQLiteCommand(); pullall.CommandText = string.Format("SELECT * FROM {0}", role.SiteItem_Table); pullall.Connection = db; log.Debug(pullall.CommandText); try { db.Open(); SQLiteDataReader reader = pullall.ExecuteReader(); while (await reader.ReadAsync()) { SiteCommandList.Add(new SiteDBPull() { URL = reader["URL"].ToString(), Parent = reader["Parent"].ToString(), Child_1 = reader["Child_1"].ToString(), Child_2 = reader["Child_2"].ToString() }); } db.Close(); } catch (Exception e) { log.Error(e); var temp = Helpers.MetroMessageBox.Show("ERMAHGERD ERER!", e.ToString()); Model.ExceptionReporting.Email(e); db.Close(); } List <SiteDBPull> Root_uniqueitems = SiteCommandList.GroupBy(s => s.Parent).Select(p => p.First()).ToList(); List <SiteDBPull> Site1uniqueitems = SiteCommandList.GroupBy(s => s.Child_1).Select(p => p.First()).ToList(); List <SiteDBPull> Site2uniqueitems = SiteCommandList.GroupBy(s => s.Child_2).Select(p => p.First()).ToList(); #region Fill Site var root = new Siteitem() { Title = "Menu" }; if (Root_uniqueitems.Count > 1) { foreach (SiteDBPull item in Root_uniqueitems) { Siteitem Root_Item = new Siteitem() { Title = item.Parent, Content = item.URL }; if (Site1uniqueitems.Count > 1) { foreach (SiteDBPull item1 in Site1uniqueitems) { Siteitem Sub_Item_1 = new Siteitem() { Title = item1.Child_1, Content = item1.URL }; if (item1.Parent == Root_Item.Title && item1.Child_1 != string.Empty) { Root_Item.SubItems.Add(Sub_Item_1); } if (Site2uniqueitems.Count > 1) { foreach (SiteDBPull item2 in Site2uniqueitems) { Siteitem Sub_Item_2 = new Siteitem() { Title = item2.Child_2, Content = item2.URL }; if (item2.Child_1 == Sub_Item_1.Title && item2.Child_2 != string.Empty) { Sub_Item_1.SubItems.Add(Sub_Item_2); } } } } } root.SubItems.Add(Root_Item); } } Sorting(root); root.SubItems = new ObservableCollection <Siteitem>(root.SubItems.OrderBy(n => n.Title)); return(root); #endregion }