public IActionResult Subject(int id, string searchQuery)
        {
            var forum = _forumService.GetById(id);
            var posts = new List <Post>();

            posts = _postService.GetFilteredPosts(forum, searchQuery).ToList();

            var postListings = posts.Select(post => new PostListingModel {
                Id           = post.Id,
                AuthorId     = post.User.Id,
                AuthorRating = post.User.Rating,
                AuthorName   = post.User.UserName,
                Title        = post.Title,
                DatePosted   = post.Created.ToString(),
                RepliesCount = post.ReplyReplies.Count() + post.ReplyReplies.Count(),
                Forum        = BuildForumListing(post)
            });

            var model = new ForumSubjectModel {
                Posts = postListings,
                Forum = BuildForumListing(forum)
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public void AddSubject(ForumSubjectModel model)
        {
            var userId = dBEntities.PanDogUser.Single(x => x.Login.Equals(model.AuthorLogin)).UserId;
            var subj   = new ForumSubject()
            {
                subjectName = model.SubjectName,
                userId      = userId
            };

            dBEntities.ForumSubject.Add(subj);
            dBEntities.SaveChanges();
        }
Ejemplo n.º 3
0
        public List <ForumSubjectModel> GetUserSubjects(string userLogin)
        {
            var user     = dBEntities.PanDogUser.Single(x => x.Login.Equals(userLogin));
            var subjects = dBEntities.ForumSubject.Where(x => x.userId == user.UserId).ToList();
            List <ForumSubjectModel> subjectModels = new List <ForumSubjectModel>();

            foreach (var subject in subjects)
            {
                var messages = dBEntities.ForumMessage.Where(x => x.subjectId == subject.subjectId).ToList();
                var subj     = new ForumSubjectModel()
                {
                    SubjectId   = subject.subjectId,
                    SubjectName = subject.subjectName,
                    messages    = messages,
                    AuthorLogin = user.Login
                };
                subjectModels.Add(subj);
            }
            return(subjectModels);
        }