예제 #1
0
        /// <summary>
        /// Gets all the posts posted by channels that a person follows
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public List <Post> GetFollowedPosts(int userID)
        {
            ChannelRepo    cr = new ChannelRepo();
            List <Channel> followedChannels = cr.GetFollowedChannels();
            List <Post>    feed             = new List <Post>();

            foreach (Channel ch in followedChannels)
            {
                feed.AddRange(db.Posts.Where(p => p.ChannelID == ch.ChannelID && p.IsDeleted == false).OrderByDescending(p => p.CreateTime).ToList());
            }
            return(feed);
        }
예제 #2
0
        /// <summary>
        /// Gets all the posts posted by channels that a person follows in a specific day range
        /// </summary>
        /// <param name="userID">user id</param>
        /// <param name="dayRange">maximum oldness of post</param>
        /// <returns></returns>
        public List <Post> GetFollowedPosts(int userID, double dayRange)
        {
            ChannelRepo    cr = new ChannelRepo();
            List <Channel> followedChannels = cr.GetFollowedChannels(userID);
            List <Post>    feed             = new List <Post>();

            if (followedChannels != null)
            {
                DateTime compare = DateTime.Now.AddDays(-dayRange);
                foreach (Channel ch in followedChannels)
                {
                    feed.AddRange(db.Posts.Where(p => p.ChannelID == ch.ChannelID && p.IsDeleted == false && p.CreateTime.CompareTo(compare) > 0).OrderByDescending(p => p.CreateTime).ToList());
                }
            }
            if (feed.Count < 1)
            {
                feed = GetFollowedPosts(userID, dayRange + 1);
            }
            return(feed);
        }