コード例 #1
0
        public void Insert(Article article)
        {
            if (article.Url == null)
            { throw new NotImplementedException("You cannot insert empty article"); }

            db.Articles.Add(article);
            db.SaveChanges();
            
        }
コード例 #2
0
 public void Update(Article article)
 {
     var dbItem = db.Articles.FirstOrDefault(x => x.Id == article.Id);
     if (dbItem == null) throw new ArgumentNullException("Not possible to delete empty article");
     dbItem.DatePublished = article.DatePublished;
     dbItem.EditionName = article.EditionName;
     dbItem.Title = article.Title;
     dbItem.Context = article.Context;
     dbItem.Author = article.Author;
     dbItem.Url = article.Url;
     db.SaveChanges();
 }
コード例 #3
0
        public static Article CreateArticle(string url) {
            string htmlText = GetWebText(url);
            Article result = new Article();
            if (htmlText != null)
            {
                result.Url = url;

                if (!htmlText.Contains("Вопрос-ответ") || !htmlText.Contains("Ответ редакции"))
                {
                    result.isQuestionAnswer = "No";
                    result.Title = getArticleTitle(htmlText);
                    result.Author = getArticleAuthor(htmlText);
                    result.DatePublished = getArticleDate(htmlText);
                    result.Context = getArticleContent(htmlText);
                    result.EditionName = getEditionName(htmlText);
                }
                else {
                    result.isQuestionAnswer = "Yes";
                    result.Title = QAServices.getQATitle(htmlText);
                    result.EditionName = QAServices.getQAEditionName(htmlText);
                    result.Author = QAServices.getQAAuthor(htmlText);
                    result.DatePublished = QAServices.getQADate(htmlText);                
                    result.Context = QAServices.getQAContent(htmlText);                
                }
            }
            return result;  
        }