Пример #1
0
        public static void CheckFeed(Blog blog)
        {
            // set up the database
            planetcsharpEntities db = new planetcsharpEntities();

            // Check a specific feed for an update
            XmlReader reader = XmlReader.Create(blog.FeedUrl);
            SyndicationFeed feed = SyndicationFeed.Load(reader);

            // loop through the feed items we've just retrieved
            foreach (var item in feed.Items)
            {
                // Test to see if the post is already in our database
                var postUrl = item.Links[0].Uri.OriginalString;
                if (!db.Posts.Any(p => p.Url == postUrl))
                {
                    // If the post is not in the db, add it
                    var newPost = new Post
                    {
                        BlogID = blog.ID,
                        Url = item.Links[0].Uri.OriginalString,
                        Title = item.Title.Text,
                        Content = item.Summary.Text,
                        PostedDate = item.PublishDate.DateTime,
                        CreatedAt = DateTime.Now
                    };
                    db.AddToPosts(newPost);
                }
            }
            db.SaveChanges();
        }
Пример #2
0
        public ActionResult Create(Post post)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Posts.AddObject(post);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }

                // Return the view if there is a validation error
                return View();
            }
            catch
            {
                return View();
            }
        }
Пример #3
0
 /// <summary>
 /// Create a new Post object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="url">Initial value of the Url property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="blogID">Initial value of the BlogID property.</param>
 /// <param name="createdAt">Initial value of the CreatedAt property.</param>
 public static Post CreatePost(global::System.Int32 id, global::System.String url, global::System.String title, global::System.Int32 blogID, global::System.DateTime createdAt)
 {
     Post post = new Post();
     post.ID = id;
     post.Url = url;
     post.Title = title;
     post.BlogID = blogID;
     post.CreatedAt = createdAt;
     return post;
 }
Пример #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Posts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPosts(Post post)
 {
     base.AddObject("Posts", post);
 }