public void ApplyChange(IResourceContext resource, ChangeEventArgs ev) { var book = resource.RequireValue <Book>(); var revert = new Dictionary <string, object>(ev.ChangedProperties.Count); if (ev.ChangedProperties.TryGetValue("title", out object titleObject)) { string title = (string)titleObject; if (title == "") { throw new ResException("Title must not be empty."); } if (title != book.Title) { revert["title"] = book.Title; book.Title = title; } } if (ev.ChangedProperties.TryGetValue("author", out object authorObject)) { string author = (string)authorObject; if (author == "") { throw new ResException("Author must not be empty."); } if (author != book.Author) { revert["author"] = book.Author; book.Author = author; } } ev.SetRevert(revert); }
// Applies the changes to the database. public void ApplyChange(IResourceContext resource, ChangeEventArgs ev) { var customer = resource.RequireValue <Customer>(); var revert = new Dictionary <string, object>(ev.ChangedProperties.Count); // Apply Name if (ev.ChangedProperties.TryGetValue("name", out object nameObject)) { string name = (string)nameObject; if (name != customer.Name) { revert["name"] = customer.Name; customer.Name = name; } } // Apply Email if (ev.ChangedProperties.TryGetValue("email", out object emailObject)) { string email = (string)emailObject; if (email != customer.Email) { revert["email"] = customer.Email; customer.Email = email; } } // Apply Country if (ev.ChangedProperties.TryGetValue("country", out object countryObject)) { string country = (string)countryObject; if (country != customer.Country) { revert["country"] = customer.Country; customer.Country = country; } } // Update the database if there are any changes to apply if (revert.Count > 0) { customers.Update(customer); } ev.SetRevert(revert); }