Fixed path construction of sections
- Fixed missed loading of parents - Made processing async
This commit is contained in:
parent
2b5de0aa1e
commit
0adc95b016
@ -138,13 +138,21 @@ public static class SectionProcessor
|
|||||||
|
|
||||||
public static Section GetSection(DataContext db, string sectionKey) => db.Sections.First(n => n.DataKey == sectionKey);
|
public static Section GetSection(DataContext db, string sectionKey) => db.Sections.First(n => n.DataKey == sectionKey);
|
||||||
|
|
||||||
public static string GetSectionPath(DataContext db, string sectionKey)
|
public static async Task<string> GetSectionPath(DataContext db, string sectionKey)
|
||||||
{
|
{
|
||||||
var section = db.Sections.First(n => n.DataKey == sectionKey);
|
var section = await db.Sections.FirstAsync(n => n.DataKey == sectionKey);
|
||||||
|
|
||||||
|
// Ensure, that the database loaded the section's parent:
|
||||||
|
await db.Entry(section).Reference(n => n.Parent).LoadAsync();
|
||||||
|
|
||||||
var path = section.Name;
|
var path = section.Name;
|
||||||
while (section.Parent != null)
|
while (section.Parent != null)
|
||||||
{
|
{
|
||||||
section = section.Parent;
|
section = await db.Sections.FirstAsync(n => n.DataKey == section.Parent.DataKey);
|
||||||
|
|
||||||
|
// Ensure, that the database loaded the section's parent:
|
||||||
|
await db.Entry(section).Reference(n => n.Parent).LoadAsync();
|
||||||
|
|
||||||
path = $"{section.Name}/{path}";
|
path = $"{section.Name}/{path}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,14 +26,14 @@ public partial class TextElements : UserControl
|
|||||||
this.Disposed += (_, _) => this.db.Dispose();
|
this.Disposed += (_, _) => this.db.Dispose();
|
||||||
|
|
||||||
// When the section is changed, update this component:
|
// When the section is changed, update this component:
|
||||||
AppEvents.WhenSectionChanged += (sender, section) =>
|
AppEvents.WhenSectionChanged += async (sender, section) =>
|
||||||
{
|
{
|
||||||
this.currentSection = section;
|
this.currentSection = section;
|
||||||
this.buttonAdd.Enabled = this.currentSection is not null;
|
this.buttonAdd.Enabled = this.currentSection is not null;
|
||||||
|
|
||||||
// Update the path:
|
// Update the path:
|
||||||
if (this.currentSection is not null)
|
if (this.currentSection is not null)
|
||||||
this.labelSectionPath.Text = SectionProcessor.GetSectionPath(this.db, this.currentSection.DataKey);
|
this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.db, this.currentSection.DataKey);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user