Esempio n. 1
0
        private Article LoadArticle(Thread thread, XElement article)
        {
            Article post = new Article();
            post.ID = (int)article.Attribute("id");
            post.ThreadID = thread.ID;
            post.Link = article.Attribute("link").Value;
            post.PostDate = DateTime.Parse(article.Attribute("postdate").Value,
                                           System.Globalization.CultureInfo.CurrentCulture,
                                           System.Globalization.DateTimeStyles.AdjustToUniversal);
            post.EditDate = DateTime.Parse(article.Attribute("editdate").Value,
                                           System.Globalization.CultureInfo.CurrentCulture,
                                           System.Globalization.DateTimeStyles.AdjustToUniversal);
            post.NumEdits = (int)article.Attribute("numedits");
            post.Subject = article.Element("subject").Value;
            post.Body = article.Element("body").Value;

            var userOutcome = Saver.GetNewOrUpdatedUser(article.Attribute("username").Value, post.PostDate);

            if (userOutcome.Failure)
                post.UserID = 0;

            post.UserID = userOutcome.Value.ID;

            return post;
        }
        public int SaveArticle(Article article)
        {
            Article existingArticle = Db.Articles.FirstOrDefault(t => t.ID == article.ID);

            if (existingArticle != null)
                return article.ID;

            Db.Articles.Add(article);
            Db.SaveChanges();

            return article.ID;
        }
Esempio n. 3
0
        private Article LoadArticleValues(int ThreadID, XElement article)
        {
            Article post = new Article();
            post.ID = (int)article.Attribute("id");
            post.ThreadID = ThreadID;
            post.UserName = article.Attribute("username").Value;
            post.Link = article.Attribute("link").Value;
            post.PostDate = DateTime.Parse(article.Attribute("postdate").Value,
                                           System.Globalization.CultureInfo.CurrentCulture,
                                           System.Globalization.DateTimeStyles.AdjustToUniversal);
            post.EditDate = DateTime.Parse(article.Attribute("editdate").Value,
                                           System.Globalization.CultureInfo.CurrentCulture,
                                           System.Globalization.DateTimeStyles.AdjustToUniversal);
            post.NumEdits = (int)article.Attribute("numedits");
            post.Subject = article.Element("subject").Value;
            post.Body = article.Element("body").Value;

            Db.Articles.Add(post);
            Db.SaveChanges();

            return post;
        }