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(); }
public ActionResult Create(Blog blog) { try { if (ModelState.IsValid) { db.Blogs.AddObject(blog); db.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
/// <summary> /// Create a new Blog object. /// </summary> /// <param name="id">Initial value of the ID property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="feedUrl">Initial value of the FeedUrl property.</param> /// <param name="blogUrl">Initial value of the BlogUrl property.</param> public static Blog CreateBlog(global::System.Int32 id, global::System.String name, global::System.String feedUrl, global::System.String blogUrl) { Blog blog = new Blog(); blog.ID = id; blog.Name = name; blog.FeedUrl = feedUrl; blog.BlogUrl = blogUrl; return blog; }
/// <summary> /// Deprecated Method for adding a new object to the Blogs EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToBlogs(Blog blog) { base.AddObject("Blogs", blog); }