public static void UpdateAuthorActiveStatus() { var allAuthors = OnixAuthorsSearchService.GetAllAuthorSearchItems(); var allBooks = OnixBooksSearchService.GetBooks(); foreach (var Author in allAuthors) { string authorSitecoreId = Author.ItemId.ToString(); var IfHasRelatedActiveBooks = allBooks.Where(b => ((b.Authors != null && b.Authors.Contains(authorSitecoreId)) || (b.Illustrators != null && b.Illustrators.Contains(authorSitecoreId))) && (b.PublishStatus == "Forthcoming" || b.PublishStatus == "Active")).Any(); if (IfHasRelatedActiveBooks) { UpdateActiveStatusField(authorSitecoreId, IfHasRelatedActiveBooks); } } }
/// <summary> /// Import books' data into sitecore and create new items /// </summary> /// <param name="books">Books obejcts generated from XML</param> public void ImportBookItemsToSitecore(List <Book> books) { ExistingBooks = OnixBooksSearchService.GetAllBooksISBN(); ExistingAuthors = OnixAuthorsSearchService.GetAllAuthorsNames(); ExistingPublishers = OnixPublishersSearchService.GetAllPublishersNames(); ExistingSeries = OnixSeriesSearchService.GetAllSeriesNames(); foreach (var book in books) { try { string bookName = ItemNameHelper.RemoveSpecialCharacters(book.Title.TitleText); if (!ExistingBooks.Contains(book.ISBN)) { ExistingBooks.Add(book.ISBN); this.CreateBookItemInSitecore(book, bookName); } else { var bookSearchItem = OnixBooksSearchService.GetBookByIsbn(book.ISBN); if (bookSearchItem != null) { Item bookItem = bookSearchItem.GetItemFromMasterDb(); if (bookItem != null) { BooksImportLog.Info(string.Format("Updating existing book [{0}] with item ID: {1}", book.Title.TitleText, bookItem != null ? bookItem.ID.ToString() : "")); this.ExtractDataToBookItem(book, bookItem); } } } Thread.Sleep(100); } catch (Exception ex) { BooksImportLog.Error("There is an error when trying to import book " + book.Title.TitleText + " in the loop", ex); } } }