Ejemplo n.º 1
0
        private List<BlogPost> GetPosts()
        {
            var blogDataItems = PopulateSideBar();
            var xmlFeed = XDocument.Load(Server.MapPath(Url.Content("/Content/TestFeed.aspx")));
            //var xmlFeed = XDocument.Load("http://blogs.medifastcommunity.com/Blogs/Icestorm0141/Atom.aspx");
            XNamespace xmlns = "http://www.w3.org/2005/Atom";

            var items = xmlFeed.Descendants(xmlns + "feed")
                          .Elements(xmlns + "entry");
            foreach (var item in items)
            {
                var existsInDb = blogDataItems.Any(p => p.Title == item.Element(xmlns + "title").Value);
                if (!existsInDb)
                {
                    var feedItem = new BlogPost()
                    {
                        DatePublished = DateTime.Parse(item.Element(xmlns + "published").Value).ToUniversalTime().AddHours(12),
                        Title = item.Element(xmlns + "title").Value,
                        PostContent = item.Element(xmlns + "content").Value
                    };
                    LibraryContext.BlogPosts.Add(feedItem);
                    blogDataItems.Add(feedItem);
                }
            }
            LibraryContext.SaveChanges();
            ViewBag.Posts = blogDataItems;
            ViewBag.PostTitle = blogDataItems.OrderByDescending(p => p.DatePublished).First().Title;
            return blogDataItems.OrderByDescending(p => p.DatePublished).ToList();
            //Atom10FeedFormatter xmlFeed = new Atom10FeedFormatter();
            //using (XmlReader reader = XmlReader.Create("http://blogs.medifastcommunity.com/Blogs/Icestorm0141/Atom.aspx"))
            //{
            //    xmlFeed.ReadFrom(reader);
            //}

            //return xmlFeed.Feed.Items
            //              .Select(item => new BlogFeed()
            //              {
            //                  PublishDate = item.PublishDate.DateTime,
            //                  Title = item.Title.Text,
            //                  Content = item.Content.ToString()
            //              })
            //              .ToList();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the BlogPosts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBlogPosts(BlogPost blogPost)
 {
     base.AddObject("BlogPosts", blogPost);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new BlogPost object.
 /// </summary>
 /// <param name="postId">Initial value of the PostId property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="datePublished">Initial value of the DatePublished property.</param>
 /// <param name="postContent">Initial value of the PostContent property.</param>
 public static BlogPost CreateBlogPost(global::System.Int32 postId, global::System.String title, global::System.DateTime datePublished, global::System.String postContent)
 {
     BlogPost blogPost = new BlogPost();
     blogPost.PostId = postId;
     blogPost.Title = title;
     blogPost.DatePublished = datePublished;
     blogPost.PostContent = postContent;
     return blogPost;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the BlogPosts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBlogPosts(BlogPost blogPost)
 {
     base.AddObject("BlogPosts", blogPost);
 }