コード例 #1
0
        public ActionResult Create(string articleTitle, string articleAuthor, string articleContent)
        {
            Article newArticle = new Article(articleTitle, articleContent);

            newArticle.Save();
            newArticle.AddSearchStrings();

            Author author = new Author(articleAuthor);

            author.Save();

            newArticle.AddAuthor(author);
            List <Article> allArticles = Article.GetAll();

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public async Task <string> CreateAsync(ArticleViewModel articleVM)
        {
            Article domain = new Article(articleVM.Url, articleVM.PublishDate, articleVM.Name);

            domain.SetConfirmation(false);
            foreach (var a in articleVM.Authors)
            {
                var foundAuthor = await db.People.FindAsync(a.Id).ConfigureAwait(false);

                if (foundAuthor == null)
                {
                    throw new ArgumentOutOfRangeException($"No person find with id {a.Id}");
                }
                else
                {
                    domain.AddAuthor(foundAuthor.ToOwned());
                }
            }
            db.Articles.Add(domain);
            await db.SaveChangesAsync().ConfigureAwait(false);

            return(domain.Id);
        }
コード例 #3
0
        private List <Article> MapArticlesToDomain(List <ArticleItemDto> dtoList)
        {
            List <Article> articles = new List <Article>();

            if (dtoList == null || dtoList.Count < 1)
            {
                return(articles);
            }

            DateTime scrapedDate = DateTime.Now;

            var predefinedSubjectItems = _context.SubjectItems.ToList();

            foreach (var dto in dtoList)
            {
                try
                {
                    Article article = new Article(dto.ArxivId,
                                                  dto.AbstractUrl,
                                                  dto.PdfUrl,
                                                  dto.OtherFormatUrl,
                                                  dto.Title,
                                                  dto.AbstractText,
                                                  dto.Comments,
                                                  string.Empty,
                                                  string.Empty,
                                                  scrapedDate);

                    if (dto.Authors != null && dto.Authors.Count > 0)
                    {
                        foreach (var author in dto.Authors)
                        {
                            article.AddAuthor(author.FullName.Trim()
                                              , author.ContextUrl?.RegexFindInBetweenStrings("+", "/"));
                        }
                    }

                    if (dto.PrimarySubject != null && dto.PrimarySubject.Length == 2)
                    {
                        var existingPrimary = predefinedSubjectItems
                                              .FirstOrDefault(si =>
                                                              si.Code == dto.PrimarySubject[1].Trim() &&
                                                              si.IsPrimary);

                        if (existingPrimary != null)
                        {
                            article.AddSubjectItem(existingPrimary);
                            dto.SubjectItems.RemoveAll(s => s.Code == existingPrimary.Code);
                        }
                        else
                        {
                            /*Only used if the database hasn't been seeded */
                            article.CreatePrimarySubject(dto.PrimarySubject[1].Trim()
                                                         , dto.PrimarySubject[0].Trim());
                            dto.SubjectItems.RemoveAll(s => s.Code == existingPrimary.Code);
                        }
                    }

                    if (dto.SubjectItems != null && dto.SubjectItems.Count > 0)
                    {
                        foreach (var sItem in dto.SubjectItems)
                        {
                            var existing = predefinedSubjectItems
                                           .FirstOrDefault(si =>
                                                           si.Code == sItem.Code && si.IsPrimary == false);

                            if (existing != null)
                            {
                                article.AddSubjectItem(existing);
                            }
                            else
                            {
                                /*Only used if the database hasn't been seeded */
                                article.CreateSubjectItem(sItem.Code.Trim(),
                                                          sItem.Description.Trim());
                            }
                        }
                    }

                    article.AddDisplayDate(GetDisplayDateString(dto.H3HeaderText, dto.DateContextInfo));

                    article.AddScrapeContext(dto.PageHeaderInfo, dto.ArxivIdLabel, dto.H3HeaderText);

                    articles.Add(article);
                }
                catch (Exception) { }
            }

            return(articles);
        }