示例#1
0
        public ActionResult NewTweetsSince(long lastTweetId, string search, SearchOrder? order)
        {
            SearchOrder searchOrder = order.GetValueOrDefault(SearchOrder.Latest);

            IPagedList<TweetReport> tweets = TweetRepository.Search(App, 1, 20, Tweeter, search,
                searchOrder != SearchOrder.Latest, DefaultLanguage, searchOrder, lastTweetId);

            TweetViewList tweetList = new TweetViewList("", tweets.TotalItems, tweets.PageNumber, tweets.ItemsPerPage);
            tweetList.SearchTerm = String.IsNullOrWhiteSpace(search) ? null : search;

            foreach (TweetReport tweet in tweets)
            {
                TweetView tweetView = new TweetView()
                {
                    Id = tweet.Id,
                    TwitterId = tweet.TwitterId,
                    Username = tweet.Username,
                    ProfileImageUrl = tweet.ProfileImageUrl,
                    Message = tweet.Message,
                    DatePosted = tweet.DatePosted,
                    DeviceName = tweet.DeviceName,
                    DeviceUrl = tweet.DeviceUrl,
                    TotalVotes = (int)tweet.TotalVotes,
                    HasBeenVotedByUser = tweet.HasBeenVotedByUser
                };

                tweetList.Tweets.Add(tweetView);
            }

            return PartialView("Tweet", tweetList);
        }
示例#2
0
        protected ActionResult Display(string pageTitle, DisplayFormat format, SearchOrder order, bool votedOnly, int? page, string search)
        {
            int pageNumber = page.GetValueOrDefault(1);

            if (format == DisplayFormat.Rss)
            {
                pageNumber = 1;
            }

            IPagedList<TweetReport> tweets = TweetRepository.Search(App, pageNumber, 20, Tweeter, search, votedOnly, DefaultLanguage, order, null);

            TweetViewList tweetList = new TweetViewList(pageTitle, tweets.TotalItems, tweets.PageNumber, tweets.ItemsPerPage);
            tweetList.SearchTerm = String.IsNullOrWhiteSpace(search) ? null : search;

            foreach (TweetReport tweet in tweets)
            {
                TweetView tweetView = new TweetView()
                {
                    Id = tweet.Id,
                    TwitterId = tweet.TwitterId,
                    Username = tweet.Username,
                    ProfileImageUrl = tweet.ProfileImageUrl,
                    Message = tweet.Message,
                    DatePosted = tweet.DatePosted,
                    DeviceName = tweet.DeviceName,
                    DeviceUrl = tweet.DeviceUrl,
                    TotalVotes = (int)tweet.TotalVotes,
                    HasBeenVotedByUser = tweet.HasBeenVotedByUser
                };

                tweetList.Tweets.Add(tweetView);
            }

            if (format == DisplayFormat.Html)
            {
                return View(tweetList);
            }
            else if (format == DisplayFormat.HtmlSnippet)
            {
                return PartialView("Tweet", tweetList);
            }
            else if (format == DisplayFormat.Json)
            {
                return Json(tweetList, JsonRequestBehavior.AllowGet);
            }
            else if (format == DisplayFormat.Rss)
            {
                string rssTitle = pageTitle;

                if (!String.IsNullOrWhiteSpace(search))
                {
                    rssTitle += " Containing \"" + search + "\"";
                }

                rssTitle += " - " + App.Title;

                RssResult<TweetView> rssResult = new RssResult<TweetView>(rssTitle, "http://" + App.Url, App.Blurb);

                rssResult.DataSource = tweetList.Tweets;

                Uri requestUrl = Request.Url;
                string baseUrl = "http://" + requestUrl.Host + (requestUrl.Port != 80 ? ":" + requestUrl.Port : "");

                rssResult.SetDataSourceFields(t => t.Message, t => baseUrl + Url.Action("Status", new { twitterId = t.TwitterId, message = t.Message.ToFriendlyUrl() }),
                    t => "@" + t.Username + " tweeted \"" + t.Message + "\"", t => "@" + t.Username, t => t.DatePosted);

                return rssResult;
            }
            else
            {
                throw new NotSupportedException(format + " is not supported");
            }
        }