Example #1
0
        public IEnumerable <PostModel> GetThreadPosts(int threadId)
        {
            using (var db = new RsdnDbContext())
            {
                var threadPosts = from post in db.Posts
                                  where post.ThreadId == threadId || post.Id == threadId
                                  join rating in db.Ratings on post.Id equals rating.PostId into ratings
                                  orderby post.Posted ascending
                                  select new PostModel
                {
                    Id               = post.Id,
                    ThreadId         = post.ThreadId,
                    SubthreadId      = post.SubthreadId,
                    Title            = post.Title,
                    Message          = post.Message,
                    Updated          = post.Updated,
                    Posted           = post.Posted,
                    Username         = post.Username,
                    InterestingCount = ratings.Count(r => r.Value == (int)VoteValue.Interesting),
                    ThanksCount      = ratings.Count(r => r.Value == (int)VoteValue.Thanks),
                    ExcellentCount   = ratings.Count(r => r.Value == (int)VoteValue.Excellent),
                    AgreedCount      = ratings.Count(r => r.Value == (int)VoteValue.Agreed),
                    DisagreedCount   = ratings.Count(r => r.Value == (int)VoteValue.Disagreed),
                    Plus1Count       = ratings.Count(r => r.Value == (int)VoteValue.Plus1),
                    FunnyCount       = ratings.Count(r => r.Value == (int)VoteValue.Funny),
                };

                return(threadPosts.ToArray());
            }
        }
Example #2
0
 public IEnumerable <ForumModel> GetForums()
 {
     using (var db = new RsdnDbContext())
     {
         return(mapper.Map <IEnumerable <ForumModel> >(db.Forums));
     }
 }
Example #3
0
 public ForumModel GetForum(int forumId)
 {
     using (var db = new RsdnDbContext())
     {
         var forum = db.Forums.Find(forumId);
         return(mapper.Map <ForumModel>(forum));
     }
 }
Example #4
0
 public ThreadModel GetThread(int threadId)
 {
     using (var db = new RsdnDbContext())
     {
         var thread = db.Threads.Find(threadId);
         return(mapper.Map <ThreadModel>(thread));
     }
 }
Example #5
0
 public void MarkForumAsVisited(int forumId)
 {
     using (var db = new RsdnDbContext())
     {
         var forum = db.Forums.Find(forumId);
         forum.Visited = DateTime.UtcNow;
         updatePolicy.Execute(() => db.SaveChanges());
     }
 }
Example #6
0
 private void ChangeFavorite(int forumId, bool flag)
 {
     using (var db = new RsdnDbContext())
     {
         var forum = db.Forums.Find(forumId);
         forum.IsFavorite = flag;
         db.SaveChanges();
     }
 }
Example #7
0
 public void MarkThreadAsViewed(int threadId)
 {
     using (var db = new RsdnDbContext())
     {
         var thread = db.Threads.Find(threadId);
         thread.Viewed       = DateTime.UtcNow;
         thread.NewPostCount = 0;
         updatePolicy.Execute(() => db.SaveChanges());
     }
 }
Example #8
0
        public IEnumerable <ForumStatus> GetForumsStatus()
        {
            using (var db = new RsdnDbContext())
            {
                var forumsStatus = from forum in db.Forums
                                   select new ForumStatus(forum.Id, forum.IsFavorite,
                                                          forum.Fetched, forum.Visited,
                                                          forum.Posted, forum.PostCount);

                return(forumsStatus.ToArray());
            }
        }
Example #9
0
        public IEnumerable <ForumModel> GetRecentForums()
        {
            using (var db = new RsdnDbContext())
            {
                IQueryable <DbForum> forums = from forum in db.Forums
                                              where forum.Visited != null && forum.IsFavorite == false
                                              orderby forum.Visited descending
                                              select forum;
                forums = forums.Take(MaxSidebarForumCount);

                return(mapper.Map <IEnumerable <ForumModel> >(forums.ToArray()));
            }
        }
Example #10
0
        public IEnumerable <ThreadModel> GetThreads(int forumId)
        {
            using (var db = new RsdnDbContext())
            {
                var threads = from post in db.Posts
                              where post.ThreadId == null && post.ForumId == forumId
                              join rating in db.Ratings on post.Id equals rating.ThreadId into ratings
                              join thread in db.Threads on post.Id equals thread.ThreadId
                              orderby post.Updated descending, post.Posted descending
                select post.CreateThreadModel(thread, ratings, this.credentialMan.User.Id, null);

                return(threads.ToArray());
            }
        }
Example #11
0
        public IEnumerable <ThreadModel> GetActivity(int userId)
        {
            using (var db = new RsdnDbContext())
            {
                var posts = from post in db.Posts
                            join rating in db.Ratings on post.Id equals rating.PostId into ratings
                            join parent in db.Posts on post.SubthreadId equals parent.Id into parents
                            join thread in db.Threads on post.ThreadId equals thread.ThreadId
                            orderby post.Updated descending, post.Posted descending
                from parent in parents.DefaultIfEmpty()
                where post.UserId == userId || parent.UserId == userId
                select post.CreateThreadModel(thread, ratings, userId, parent);

                return(posts.ToArray());
            }
        }
Example #12
0
        public IEnumerable <GroupModel> GetGroups()
        {
            using (var db = new RsdnDbContext())
            {
                var groups = db.Groups.ToArray();
                var forums = db.Forums.ToArray();

                var forumsInGroups = from g in groups
                                     join f in forums on g.Id equals f.GroupId into groupForums
                                     orderby g.SortOrder
                                     select new GroupModel
                {
                    Id        = g.Id,
                    Name      = g.Name,
                    SortOrder = g.SortOrder,
                    Forums    = mapper.Map <IEnumerable <DbForum>, IEnumerable <ForumModel> >(
                        from gf in groupForums
                        orderby gf.Name
                        select gf)
                };

                return(forumsInGroups.ToArray());
            }
        }