public ActionResult AddNewComment(CommentModel model)
        {
            if (model.CommentDescription.Length < 2)
                return JsonErrorResult("Слишком короткий комментарий");

            var comment = new CommentData
            {
                CreateDate = DateTime.UtcNow,
                Description = model.CommentDescription,
                Rate = default(int),
                Writer = new UserData { Id = CurrentUser.Id }
            };

            Execute(() => _newsService.AddNewsComment(model.ContentId, comment));

            FillCommentModel(model);

            return ModelIsValid
                ? (ActionResult)View("_CommentDataPartial", model)
                : JsonErrorResult();
        }
        public CommentData SaveComment(CommentData data)
        {
            var entity = _commentRepository.Query(o => o.Id == data.Id).SingleOrDefault();
            if (entity == null)
                throw new ArgumentException("Данного комментария не существует.");

            entity.Description = data.Description;
            entity.ModifierDate = DateTime.UtcNow;

            UnitOfWork.Commit();

            var comment = ((IResourceService)this).GetComment(entity.Id);
            var writer = _userRepository.GetData(o => new UserData
            {
                Id = o.Id,
                UserName = o.UserName,
                PhotoPath = o.PhotoPath,
                RoleId = o.RoleId
            }, o => o.Id == comment.WriterId).SingleOrDefault();

            if (writer == null)
                throw new ArgumentException("Данного пользователя не существует.");

            comment.Writer = writer;

            return comment;
        }
 public CommentItemModel()
 {
     CommentItem = new CommentData();
 }
        void INewsService.AddNewsComment(int newsId, CommentData data)
        {
            var news = _newsRepository.Query(o => o.Id == newsId).SingleOrDefault();
            if (news == null)
                throw new ArgumentException("Данной новости не существует");

            var writer = _userRepository.Query(o => o.Id == data.Writer.Id).SingleOrDefault();
            if (writer == null)
                throw new ArgumentException("Данного пользователя не существует");

            if (news.BlockComments)
                throw new ArgumentException("Добавление комментариев заблокировано");

            var comment = new Comment
            {
                CreateDate = data.CreateDate,
                Description = data.Description,
                Rate = data.Rate,
                Writer = writer
            };

            _commentRepository.Add(comment);
            _newsCommentRepository.Add(new NewsComment { News = news, Comment = comment });

            UnitOfWork.Commit();
        }