I need to implement a very simple interface, the user loads from a service a certain amount of objects displayed into a gridview. Then selecting an object in the gridview the user can edit object properties in a detail panel situated under the grid. Specification ask me to
avoid that the user update some property of the object, then forget to press Save button and move to another object forgetting to update data calling the service update function.
the system must support an undo button that restore the object properties if the user decides not to save changes.
Since the service return Dto objects that supports INotifyPropertyChanged and IEditableObject everything is a breeze. I used a custom MVC structure in winform, where the view use BindingSource objects to bind control to data, and pass BindingObjects to the controller to interact with current object. The first step is intercepting when the users begins editing of an object.
The controller simply set the list of Action to the view, then save the BindingSource (created by designer) then intercept CurrentChanged and fire the ChangeSelectedActionFromList. My view was designed in this way: when controller call SetLisOfAction it assign the list of actionDto to a bindingSource and then returns it to the caller. LEts see how to react at change of current element.
This function simply verify if the current object is different from null, if yes it intercept propertyChanged and call BeginEditOfAnAction in the view.
The view reacts disabling the grid, so the user cannot move from current record until he choose to save or cancel current editing. Here is the two actions of the controller
Update Action simply calls a service to update the action, if the action is successful it show an UpdateOk message then end the edit of the action and the edit of the BindingSource. If the user press cancel simply cancel edit of binding source. This is because my dto object supports both INotifyPropertyChanged and IEditableObject.