The following code basically updates the book list in the selected storage space if it already contains the specific book (after confirming with the user). Otherwise, it will add the book to the book list as a new book:
private void UpdateStorageSpaceBooks(int storageSpaceId) { try { int iCount = (from s in spaces where s.ID == storageSpaceId select s).Count(); if (iCount > 0) // The space will always exist { // Update StorageSpace existingSpace = (from s in spaces where s.ID == storageSpaceId select s).First(); List<Document> ebooks = existingSpace.BookList; int iBooksExist = (ebooks != null) ? (from b in ebooks where $"{b.FileName}".Equals($" {txtFileName.Text.Trim()}") select b).Count() : 0; if ...