internal void AddBookToSnapshot(cBook newBook) { Books.Add(newBook); var overrides = new XmlAttributeOverrides(); var attributes = new XmlAttributes(); attributes.XmlIgnore = true; string plainTextXml; newBook.Borrowed = new cBorrowed { FirstName = "", LastName = "", From = "" }; using (var sw = new StringWriter()) { var xs = new XmlSerializer(typeof(cLibrary), overrides); xs.Serialize(sw, this); plainTextXml = sw.ToString(); } XmlDocument newDoc = new XmlDocument(); newDoc.LoadXml(plainTextXml); LibraryProvider.StreamSnapshot = new MemoryStream(); LibraryProvider.StreamSnapshot.Position = 0; newDoc.Save(LibraryProvider.StreamSnapshot); LibraryProvider.StreamSnapshot.Position = 0; }
internal void EditBook(cBook newBook) { cBook originalBook = (from b in Books where b.Id == newBook.Id select b).First(); originalBook.Name = newBook.Name; originalBook.Author = newBook.Author; originalBook.Borrowed = newBook.Borrowed; UpdateSnapshotFromDataLayer(); }
internal void ReturnBook(int id) { cBook BookToReturn = (from b in Books where b.Id == id select b).First(); BookToReturn.Borrowed = null; UpdateSnapshotFromDataLayer(); }
internal void BorrowBook(int bookId, string firstName, string lastName, DateTime now) { cBook bookToAssign = (from book in Books where book.Id == bookId select book).First(); if (bookToAssign.Borrowed == null) { bookToAssign.Borrowed = new cBorrowed(); } bookToAssign.Borrowed.FirstName = firstName; bookToAssign.Borrowed.LastName = lastName; bookToAssign.Borrowed.From = now.ToString(); UpdateSnapshotFromDataLayer(); }