Added loading of section's text entries

This commit is contained in:
Thorsten Sommer 2022-07-16 22:40:06 +02:00
parent fb2f573de4
commit 32ebd69194
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 41 additions and 2 deletions

View File

@ -0,0 +1,14 @@
using System.Collections;
using DataModel.Database;
using DataModel.Database.Common;
using Microsoft.EntityFrameworkCore;
namespace Processor;
public static class TextElementProcessor
{
public static Task<IAsyncEnumerable<TextElement>> GetTextElements(DataContext db, Section section)
{
return Task.FromResult(db.TextElements.Where(n => n.Section == section).AsAsyncEnumerable());
}
}

View File

@ -32,8 +32,33 @@ public partial class TextElements : UserControl
this.buttonAdd.Enabled = this.currentSection is not null;
// Update the path:
if (this.currentSection is not null)
this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.db, this.currentSection.DataKey);
if (this.currentSection is null)
return;
this.labelSectionPath.Text = await SectionProcessor.GetSectionPath(this.db, this.currentSection.DataKey);
this.LoadTextElements();
};
}
// Loads all the text elements for the current section.
private async void LoadTextElements()
{
if (this.currentSection is null)
return;
// Load the text elements:
var textElements = await TextElementProcessor.GetTextElements(this.db, this.currentSection);
// Update the list:
this.listTextElements.Items.Clear();
await foreach (var textElement in textElements)
{
var item = new ListViewItem(textElement.Name)
{
Tag = textElement
};
this.listTextElements.Items.Add(item);
}
}
}