示例#1
0
        public IEnumerable <IArticlePurchaseItem> Create(IEnumerable <IArticlePurchase> articlePurchases)
        {
            if (articlePurchases == null || !articlePurchases.Any())
            {
                return(Enumerable.Empty <IArticlePurchaseItem>());
            }

            var filter = ArticleSearch.CreateFilter();

            filter.ArticleNumbers = articlePurchases.Select(ap => ap.DocumentId).ToList();

            var results = ArticleSearch.Search(filter);
            var articlePurchaseItems = new List <IArticlePurchaseItem>();

            foreach (var article in results.Articles)
            {
                var articlePurchase = articlePurchases.FirstOrDefault(ap => string.Equals(ap.DocumentId, article.Article_Number));

                if (articlePurchase == null)
                {
                    continue;
                }

                var url           = article._Url ?? string.Empty;
                var isExternalUrl = !IsUrlCurrentSite.Check(url);

                articlePurchaseItems.Add(new ArticlePurchaseItem
                {
                    Expiration    = articlePurchase.Expiration,
                    Publication   = articlePurchase.Publication,
                    Title         = article.Title,
                    Url           = url,
                    IsExternalUrl = isExternalUrl
                });
            }

            return(articlePurchaseItems);
        }
        public IEnumerable <ISavedDocumentItem> Create(IEnumerable <ISavedDocument> savedDocuments)
        {
            var savedDocumentItems = new List <ISavedDocumentItem>();

            foreach (var savedDocument in savedDocuments)
            {
                Guid itemId;

                if (!Guid.TryParse(savedDocument.DocumentId, out itemId))
                {
                    continue;
                }

                var item = GlobalService.GetItem <IArticle>(itemId);

                if (item == null)
                {
                    continue;
                }

                var url           = item._Url ?? string.Empty;
                var isExternalUrl = !IsUrlCurrentSite.Check(url);

                savedDocumentItems.Add(new SavedDocumentItem
                {
                    DocumentId    = savedDocument.DocumentId,
                    Publication   = FindPublication.Find(savedDocument.Description),
                    PublishedOn   = item.Actual_Publish_Date,
                    SavedOn       = savedDocument.SaveDate,
                    Title         = item.Title ?? savedDocument.Name,
                    Url           = url,
                    IsExternalUrl = isExternalUrl
                });
            }

            return(savedDocumentItems);
        }