Implemented the delete function for text elements
This commit is contained in:
parent
e762cfe21e
commit
71936e5dcf
@ -91,4 +91,23 @@ public static class TextElementProcessor
|
||||
return updateException.ToProcessorResult<TextElement>();
|
||||
}
|
||||
}
|
||||
|
||||
// Deletes a text element:
|
||||
public static async Task DeleteTextElement(int id)
|
||||
{
|
||||
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||
var textElement = await db.TextElements.FirstAsync(n => n.Id == id);
|
||||
|
||||
// Remove the element from the database:
|
||||
db.TextElements.Remove(textElement);
|
||||
|
||||
try
|
||||
{
|
||||
// Save the changes:
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateException updateException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -102,9 +102,20 @@ public partial class TextElements : UserControl
|
||||
this.column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
||||
}
|
||||
|
||||
private void buttonRemove_Click(object sender, EventArgs e)
|
||||
private async void buttonRemove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if(this.DesignMode || this.currentTextElement is null)
|
||||
return;
|
||||
|
||||
// Ask the user, if he really wants to remove the text element:
|
||||
if(MessageBox.Show(this.currentTextElement.Translations.Count > 0 ? $"Are you sure, you want to remove the text element '{this.currentTextElement.Name}', its {this.currentTextElement.Translations.Count} translations and so on?" : $"Are you sure, you want to remove the text element '{this.currentTextElement.Name}'?", "Remove text element", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
|
||||
return;
|
||||
|
||||
// Remove the text element1 from the database:
|
||||
await TextElementProcessor.DeleteTextElement(this.currentTextElement.Id);
|
||||
|
||||
// Reload the data:
|
||||
await this.LoadTextElements();
|
||||
}
|
||||
|
||||
private async void buttonRename_Click(object sender, EventArgs e)
|
||||
|
Loading…
Reference in New Issue
Block a user