예제 #1
0
        private GetCommentsModel GenerateGetCommentsModel(int postId)
        {
            var commentaryService = new CommentaryService();
            var comments          = commentaryService.SearchCommentsByIdPost(new SearchCommentsByIdPostRequest()
            {
                IdPost = postId
            }).Comments;

            var commentsResult = new GetCommentsModel();

            commentsResult.Comments = new List <CommentaryModel>();

            foreach (var commentary in comments)
            {
                if (!commentary.IdUpperComment.HasValue)
                {
                    var commentaryToAdd = TheModelFactory.CreateCommentaryModel(commentary);
                    commentaryToAdd.Answers = new List <AnswerModel>();
                    foreach (var answer in comments)
                    {
                        if (answer.IdUpperComment.HasValue)
                        {
                            if (answer.IdUpperComment == commentary.Id)
                            {
                                var answerToAdd = TheModelFactory.CreateAnswerModel(answer);
                                commentaryToAdd.Answers.Add(answerToAdd);
                            }
                        }
                    }
                    commentsResult.Comments.Add(commentaryToAdd);
                }
            }

            return(commentsResult);
        }
예제 #2
0
        public ActionResult Details(int id)
        {
            var commentaryService = new CommentaryService();
            var complaintService  = new ComplaintService();
            var postService       = new PostService();
            var userService       = new UserService();
            var votesService      = new VoteService();

            var post = postService.GetPostById(new GetPostByIdRequest()
            {
                Id = id
            }).Post;

            // Se obtienen los comentarios del post y se los separa en comentarios padre y respuestas.
            var allComments = commentaryService.SearchCommentsByIdPost(new SearchCommentsByIdPostRequest()
            {
                IdPost = id
            }).Comments.Where(x => !x.NullDate.HasValue).ToList();

            ViewBag.Comments = allComments.Where(x => !x.IdUpperComment.HasValue).ToList();
            ViewBag.Replies  = allComments.Where(x => x.IdUpperComment.HasValue).ToList();

            List <Complaint> userComplaints = new List <Complaint>();

            if (User.Identity.IsAuthenticated && !User.IsInRole("Admin"))
            {
                // Se obtienen las denuncias/quejas realizadas por el usuario.
                userComplaints = complaintService.SearchComplaintsByUserId(new SearchComplaintsByUserIdRequest {
                    AspNetUserId = User.Identity.GetUserId()
                }).Complaints;

                var user = userService.GetUserByAccountId(new GetUserByAccountIdRequest {
                    AccountId = User.Identity.GetUserId()
                }).User;

                // Se obtienen los votos del post y del usuario
                var postVotes = votesService.GetVotesCountByPostId(new GetVotesCountByPostIdRequest {
                    PostId = post.Id
                });
                var userVotes = votesService.GetVoteByUserAndPostId(new GetVoteByUserAndPostIdRequest {
                    PostId = post.Id, UserId = user.Id
                });

                ViewBag.GoodVotes    = postVotes.GoodVotes;
                ViewBag.BadVotes     = postVotes.BadVotes;
                ViewBag.UserGoodVote = userVotes.Good ? "true" : "false";
                ViewBag.UserBadVote  = userVotes.Bad ? "true" : "false";
            }

            if (User.Identity.IsAuthenticated && User.IsInRole("Admin"))
            {
                ViewBag.Complaints = complaintService.SearchComplaintsByPostId(new SearchComplaintsByPostIdRequest {
                    PostId = post.Id
                }).Complaints;
            }

            ViewBag.UserComplaints = userComplaints;

            return(View(post));
        }
예제 #3
0
        public IHttpActionResult GetCommentary(int id)
        {
            try
            {
                var commentaryService = new CommentaryService();
                var comments          = commentaryService.SearchCommentsByIdPost(new SearchCommentsByIdPostRequest()
                {
                    IdPost = id
                }).Comments;

                if (!comments.Any())
                {
                    return(NotFound());
                }

                var result = GenerateGetCommentsModel(id);

                return(Ok(result));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }