public Memento(Book book) { ISBN = book.ISBN; Title = book.Title; Author = book.Author; LastEdited = book.LastEdited; }
public void TestMethod1() { Book book = new Book(); book.ISBN = "0450488357"; book.Title = "The Tommyknockers"; book.Author = "Stephen King"; book.ShowBook(); book.SaveUndo(); Thread.Sleep(1000); // Modify book book.ISBN = "0330376144"; book.Title = "The Rats"; book.Author = "James Herbert"; book.ShowBook(); book.SaveUndo(); book.PrintHistory(); book.RestoreToVersion(1); book.ShowBook(); }
private static void RestoreBook(Book book, Memento memento) { if (memento != null && book != null) { book.RestoreFromUndo(memento); } }
public void SaveUndo(Book book) { _history.Add(book.CreateUndo()); }
public void RestoreToVersion(Book book, int versionNumber) { var memento = _history.FirstOrDefault(mem => mem.VersionNumber == versionNumber); RestoreBook(book, memento); }
public void RestoreToLatestVersion(Book book) { var memento = History.LastOrDefault(); RestoreBook(book, memento); }