views:

19

answers:

1

I am working on a ASP.Net MVC website and I am querying Twitter's API to return data. I also have a database backend which returns posts for a blog.

How can I put this data in date order and parse it to the view?

At the moment I am using http://tweet.seaofclouds.com/ which puts data into a div via jQuery however I now have this added need to get data from the database and Twitter when the view is requested.

I'm thinking I can make a request to twitter in the controller when the page is requested, also at the same time get the data back from the database and then build a ViewModel and parse that to the view eg/ return View(myTwitterDBModel);

Would you do it this way or do you have a better idea?

A: 

This is what I have done using the Twitterizer library. It works but still not sure if its correct:

public ActionResult Blog()
        {
            List<Post> data = new List<Post>();

            Post p = new Post();
            p.Date = new DateTime(2009, 08, 23);
            p.Title = "Long Time Ago";
            p.Text = "Old post";

            data.Add(p);

            p = new Post();

            p.Date = DateTime.Now;
            p.Title = "New Post";
            p.Text = "BLAH BLAH ";

            data.Add(p);


            var ds = data.Select((title) => new BlogData { Title = title.Title, Date = title.Date, Text = title.Text });




            UserTimelineOptions options = new UserTimelineOptions();
            options.ScreenName = "TWIITERUSERNAME";


            TwitterStatusCollection recentTweets = TwitterTimeline.UserTimeline(options);

            ds = ds.Concat(recentTweets.Select((tweet) => new BlogData { Title = tweet.Text, Date = tweet.CreatedDate, Text = "" })).OrderByDescending(X => X.Date);




            return View(ds);
        }
Jon