Exemplo n.º 1
0
        public ActionResult DeleteComment(int? id, int? contentId, CommentSortEnum sortType)
        {
            Execute(() => _newsService.DeleteNewsComment(id.GetValueOrDefault(), CurrentUser.IsMainRole, CurrentUser.Id));

            var model = new CommentModel
            {
                ContentId = contentId.GetValueOrDefault(),
                SortType = sortType
            };

            FillCommentModel(model);
            return ModelIsValid
                ? (ActionResult)View("_CommentDataPartial", model)
                : JsonErrorResult();
        }
Exemplo n.º 2
0
        public ActionResult NewsCommentFeed(int? id, CommentSortEnum sortType)
        {
            var model = new CommentModel
            {
                ContentId = id.GetValueOrDefault(),
                SortType = sortType
            };

            FillCommentModel(model);

            return ModelIsValid
                ? (ActionResult)View("_CommentDataPartial", model)
                : JsonErrorResult();
        }
Exemplo n.º 3
0
        CommentsWrapper INewsService.GetNewsComments(int newsId, CommentSortEnum sortType)
        {
            var news = _newsRepository.Query(o => o.Id == newsId).SingleOrDefault();
            if (news == null)
                throw new ArgumentException("Данной новости не существует");

            var commentsWrap = new CommentsWrapper { ContentId = news.Id, BlockComments = news.BlockComments };

            var comments = news.NewsComments.Select(o => new CommentData
            {
                Id = o.Comment.Id,
                Description = o.Comment.Description,
                CreateDate = o.Comment.CreateDate,
                ModifierDate = o.Comment.ModifierDate,
                Rate = o.Comment.Rate,
                Writer = o.Comment.Writer != null
                    ? new UserData { Id = o.Comment.Writer.Id, UserName = o.Comment.Writer.UserName, PhotoPath = o.Comment.Writer.PhotoPath, RoleId = o.Comment.Writer.RoleId }
                    : new UserData(),
                ContentId = o.NewsId
            }).OrderByDescending(o => o.CreateDate).ToList();

            var commentIds = comments.Select(o => o.Id).ToArray();
            var userComments = _userCommentRepository.GetData(o => new UserCommentData
            {
                UserId = o.UserId,
                CommentId = o.CommentId,
                IsInc = o.IsIncrement
            }, o => o.UserId == CurrentUserId && commentIds.Contains(o.CommentId)).ToDictionary(o => o.CommentId, o => o.IsInc);

            foreach (var comment in comments.Where(comment => userComments.ContainsKey(comment.Id)))
            {
                comment.IsInc = userComments[comment.Id];
            }

            switch (sortType)
            {
                case CommentSortEnum.Old:
                    commentsWrap.Data = comments.OrderBy(o => o.CreateDate).ToList();
                    break;
                case CommentSortEnum.Popular:
                    commentsWrap.Data = comments.OrderByDescending(o => o.Rate);
                    break;
                default:
                    commentsWrap.Data = comments;
                    break;
            }

            return commentsWrap;
        }