Added a multi-line state to the text elements

This commit is contained in:
tsommer committed 2022-09-17 19:23:11 +02:00
1 parent 72aa94bed5
commit 0aeec1885f
13 files changed
+361 -29

No files matched your search

@@ -26,7 +26,7 @@ public static class TextElementProcessor
}
// Adds a new text element:
public static async Task<ProcessorResult<TextElement>> AddTextElement(string? currentSectionKey, string elementName)
public static async Task<ProcessorResult<TextElement>> AddTextElement(string? currentSectionKey, string elementName, bool isMultiLine)
{
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
@@ -45,6 +45,7 @@ public static class TextElementProcessor
Name = elementName,
Code = code,
Section = currentSection,
IsMultiLine = isMultiLine,
};
// Add the new element to the database:
@@ -62,15 +63,31 @@ public static class TextElementProcessor
}
}
// Renames a text element:
public static async Task<ProcessorResult<TextElement>> RenameTextElement(int id, string newName)
// Updates the multi-line flag of a text element:
public static async Task<ProcessorResult<TextElement>> UpdateTextElementState(int id, bool isMultiLine)
{
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
var textElement = await db.TextElements.FirstAsync(n => n.Id == id);
if (textElement is null)
throw new ArgumentOutOfRangeException(nameof(id));
textElement.IsMultiLine = isMultiLine;
try
{
// Save the changes:
await db.SaveChangesAsync();
return new ProcessorResult<TextElement>(textElement);
}
catch (DbUpdateException updateException)
{
return updateException.ToProcessorResult<TextElement>();
}
}
// Renames a text element:
public static async Task<ProcessorResult<TextElement>> RenameTextElement(int id, string newName, bool isMultiLine)
{
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
var textElement = await db.TextElements.FirstAsync(n => n.Id == id);
// Get the corresponding section:
var section = (await db.TextElements.FirstAsync(n => n.Id == id)).Section;
@@ -79,6 +96,7 @@ public static class TextElementProcessor
textElement.Name = newName;
textElement.Code = code;
textElement.IsMultiLine = isMultiLine;
// Save the changes:
try