Пример #1
0
        public ActionResult Read(int id, int?page)
        {
            var currentPage = page > 0 ? page.Value : 1;

            var postComments = this.GetPostCommentsPage(id, currentPage, GlobalConstants.DefaultPageSize);

            var viewModel = new PostCommentsPageViewModel
            {
                PostId   = id,
                Comments = postComments
            };

            return(this.PartialView("_PostComments", viewModel));
        }
Пример #2
0
        public ActionResult Create(CreateCommentInputModel inputModel)
        {
            if (inputModel != null && this.ModelState.IsValid)
            {
                var authorId = this.User.Identity.GetUserId();
                this.commentsData.AddCommentForPost(inputModel.PostId, inputModel.Content, authorId);

                var postCommentsCount = this.commentsData.GetCountByPost(inputModel.PostId);
                var lastPage          = (int)Math.Ceiling((double)postCommentsCount / GlobalConstants.DefaultPageSize);
                var commentsLastPage  = this.GetPostCommentsPage(inputModel.PostId, lastPage, GlobalConstants.DefaultPageSize);

                var viewModel = new PostCommentsPageViewModel
                {
                    PostId   = inputModel.PostId,
                    Comments = commentsLastPage
                };
                return(this.PartialView("_PostComments", viewModel));
            }

            return(this.JsonValidation());
        }