/// <summary> /// Removes a year of publishing from the years of publishing list, as well as /// from the respective books list. /// </summary> /// <param name="yearOfPublishingToRemove">The year of publishing to remove</param> public void RemoveYearOfPublishing(YearOfPublishing yearOfPublishingToRemove) { IUpdateAction removeBooksWithYearOfPublishingAction = new DummyAction(); yearsOfPublishing.Remove(yearOfPublishingToRemove); if (booksWithYearOfPublishing.ContainsKey(yearOfPublishingToRemove) == true) { removeBooksWithYearOfPublishingAction = new DeleteAction( booksWithYearOfPublishing[yearOfPublishingToRemove]); foreach (Book currentBook in booksWithYearOfPublishing[yearOfPublishingToRemove]) { currentBook.YearOfPublishing = null; } booksWithYearOfPublishing.Remove(yearOfPublishingToRemove); } try { IUpdateAction removeYearOfPublishingAction = new DeleteAction(yearOfPublishingToRemove); DatabaseManager.Instance.PerformDataUpdate(removeBooksWithYearOfPublishingAction, removeYearOfPublishingAction); } catch (DatabaseException ex) { throw new BookEntitiesException(ex.Message, ex); } }
/// <summary> /// Book constructor. /// </summary> /// <param name="discEntry">The folder and file structure, along with its corresponding /// content</param> /// <param name="entryPointPath">The path to the file entry point for the book</param> /// <param name="isFolderBased">True, if the book is folder based, /// false, if the book is file based</param> /// <param name="title">The title of the book</param> public Book(IDiscEntry discEntry, string entryPointPath, bool isFolderBased, string title) { this.discEntry = discEntry; this.entryPointPath = entryPointPath; this.isFolderBased = isFolderBased; this.title = title; this.authors = new List <Author>(); this.tags = new List <Tag>(); this.publishingHouse = null; this.yearOfPublishing = null; }
public List <Book> GetAllBooksWithYearOfPublishing(YearOfPublishing aYearOfPublishing) { List <Book> requiredBooks = new List <Book>(); if (booksWithYearOfPublishing.ContainsKey(aYearOfPublishing) == true) { foreach (Book aBook in booksWithYearOfPublishing[aYearOfPublishing]) { requiredBooks.Add(aBook); } } return(requiredBooks); }
/// <summary> /// Renames an existing year of publishing. /// </summary> /// <param name="yearOfPublishingToRename">The year of publishing to be renamed</param> /// <param name="newYear">The new year for the year of publishing</param> public void RenameYearOfPublishing(YearOfPublishing yearOfPublishingToRename, int newYear) { bool newYearExists = false; foreach (YearOfPublishing aYearOfPublishing in yearsOfPublishing) { if (aYearOfPublishing.Year == newYear) { newYearExists = true; break; } } if (newYearExists == false) { yearOfPublishingToRename.Year = newYear; yearsOfPublishing.Sort(); } }
public void SetBookYearOfPublishing(Book currentBook, YearOfPublishing bookYearOfPublishing) { if (currentBook.YearOfPublishing != null) { if (booksWithYearOfPublishing.ContainsKey(currentBook.YearOfPublishing) == true) { booksWithYearOfPublishing[currentBook.YearOfPublishing].Remove(currentBook); } } currentBook.YearOfPublishing = bookYearOfPublishing; if ((currentBook.YearOfPublishing != null) && (bookYearOfPublishing != null)) { if (booksWithYearOfPublishing.ContainsKey(bookYearOfPublishing) == true) { booksWithYearOfPublishing[bookYearOfPublishing].Add(currentBook); } } }
/// <summary> /// Adds a new year of publishing to the years of publishing list. /// </summary> /// <param name="newYearOfPublishing">The new year of publishing</param> public void AddYearOfPublishing(int newYearOfPublishing) { bool yearOfPublishingExists = false; foreach (YearOfPublishing aYearOfPublishing in yearsOfPublishing) { if (aYearOfPublishing.Year == newYearOfPublishing) { yearOfPublishingExists = true; break; } } if (yearOfPublishingExists == false) { YearOfPublishing newYearOfPublishingObject = new YearOfPublishing(newYearOfPublishing); yearsOfPublishing.Add(newYearOfPublishingObject); yearsOfPublishing.Sort(); booksWithYearOfPublishing[newYearOfPublishingObject] = new List <Book>(); } }