public IHttpActionResult GetUserTweets(string username, [FromUri] UserTweetsBindingModel model)
        {
            var loggedUserId = this.User.Identity.GetUserId();
            var loggedUser   = this.TwitterData.Users.Find(loggedUserId);

            if (loggedUser == null)
            {
                return(this.BadRequest("Invalid session token."));
            }

            if (model == null)
            {
                return(this.BadRequest());
            }

            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var targetUser = this.TwitterData.Users.All()
                             .FirstOrDefault(u => u.UserName == username);

            if (targetUser == null)
            {
                return(this.NotFound());
            }

            var candidateTweets = targetUser.OwnTweets
                                  .OrderByDescending(p => p.PostedOn)
                                  .AsQueryable();

            if (model.StartPostId.HasValue)
            {
                candidateTweets = candidateTweets
                                  .AsQueryable()
                                  .SkipWhile(p => p.Id != model.StartPostId)
                                  .Skip(1)
                                  .AsQueryable();
            }

            var userTweets = candidateTweets
                             .Take(model.PageSize)
                             .Select(t => TweetViewModel.CreateView(t, loggedUser));

            return(this.Ok(userTweets));
        }
        public IHttpActionResult GetHomePage([FromUri] NewsFeedBindingModel model)
        {
            var loggedUserId = this.User.Identity.GetUserId();
            var loggedUser   = this.TwitterData.Users.Find(loggedUserId);

            if (loggedUser == null)
            {
                return(this.BadRequest("Invalid session token."));
            }

            if (model == null)
            {
                return(this.BadRequest());
            }

            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var candidateTweets = this.TwitterData.Tweets.All()
                                  .Where(p => p.Author.Followers.Any(fr => fr.Id == loggedUserId) ||
                                         p.WallOwner.Followers.Any(fr => fr.Id == loggedUserId))
                                  .Include(p => p.Author)
                                  .Include(p => p.WallOwner)
                                  .Include(p => p.Replies)
                                  .Include(p => p.Favorites)
                                  .OrderByDescending(p => p.PostedOn)
                                  .AsEnumerable();

            if (model.StartPostId.HasValue)
            {
                candidateTweets = candidateTweets
                                  .SkipWhile(t => t.Id != model.StartPostId)
                                  .Skip(1);
            }

            var homeTweets = candidateTweets
                             .Take(model.PageSize)
                             .AsQueryable()
                             .Select(t => TweetViewModel.CreateView(t, loggedUser))
                             .ToList();

            return(this.Ok(homeTweets));
        }