Sam Hobbs

Sam Hobbs

  • 51
  • 29.1k
  • 2m

Undo an entity edit

Jan 19 2024 2:16 AM

This is for a WPF application.

Suppose I have an entity Post and I show a dialog to edit it. The dialog has Okay and Cancel buttons. The entity will be updated in the dialog. What if the Cancel button is clicked? How do I undo the changes? Obviously I can save each field and then restore each if the edit is to be canceled. Is there a more direct mechanism? The following is a simplified version of what I am doing.

Post? post = Grid.SelectedItem as Post;
if (post is null)
    return;
EditPost ep = new(post);
bool? b = ep.ShowDialog();

 


Answers (3)