public ReplyCommentViewModel(Comment parentComment) { if (parentComment != null) { ContentTitle = parentComment.Content.Title; AuthorId = parentComment.Content.AuthorId; GroupId = parentComment.Content.GroupId; AddComment = new _AddCommentViewModel { ParentCommentId = parentComment.Id, ReturnUrl = parentComment.Content.GetUrl() }; Comment = new _Comments_CommentViewModel(parentComment); } }
public static Comment AddComment(string text, Guid userId, Guid? contentId, Guid? parentCommentId) { var user = DataService.PerThread.BaseUserSet.OfType<User>().SingleOrDefault(u => u.Id == userId); if (user == null) throw new BusinessLogicException("Перезайдите"); if (string.IsNullOrWhiteSpace(text)) throw new BusinessLogicException("Не введен текст комментария"); if (!contentId.HasValue && !parentCommentId.HasValue) throw new BusinessLogicException("Неверный идентификатор поста"); var comment = new Comment { Text = text, UserId = userId }; if (parentCommentId.HasValue) { var parentComment = DataService.PerThread.CommentSet.SingleOrDefault(c => c.Id == parentCommentId); if (parentComment == null) throw new MvcActionRedirectException("Указан неверный идентификатор комментария", "error", "index");//TODO var group = parentComment.Content.Group; if (group.PrivacyEnum.HasFlag(GroupPrivacy.PrivateDiscussion) && !GroupService.IsUserApprovedInGroup(userId, group)) throw new BusinessLogicException("Комментировать могут только члены группы"); if (parentComment.IsHidden) throw new BusinessLogicException("Данный комментарий скрыт, его нельзя комментировать"); if (parentComment.ParentComment != null) { comment.ReplyTo = parentComment; comment.ParentCommentId = parentComment.ParentCommentId; comment.ContentId = parentComment.ParentComment.ContentId; } else { comment.ParentCommentId = parentCommentId; comment.ContentId = parentComment.ContentId; } } else { var content = DataService.PerThread.ContentSet.SingleOrDefault(c => c.Id == contentId); if (content == null) throw new BusinessLogicException("Указан неверный идентификатор контента"); if (content.IsDiscussionClosed) throw new BusinessLogicException("Дискуссия по данному вопросу закрыта"); comment.ContentId = contentId.Value; } DataService.PerThread.CommentSet.AddObject(comment); DataService.PerThread.SaveChanges(); //сообщение о появлении коммента DataService.PerThread.LoadProperty(comment, c => c.Content); var commentAuthorId = Guid.Empty; if (comment.ParentComment != null) { if (comment.ReplyTo == null) //Отвечаем на корень ветки { if (comment.ParentComment.UserId != comment.UserId) commentAuthorId = comment.ParentComment.UserId; } else //Отвечаем на комментарий внутри ветки { if (comment.ReplyTo.UserId != comment.UserId) commentAuthorId = comment.ReplyTo.UserId; } } else //Отвечаем на пост { if (comment.Content.AuthorId != null) if (comment.Content.AuthorId != comment.UserId) commentAuthorId = comment.Content.AuthorId.Value; } if (commentAuthorId != Guid.Empty && comment.User.BlackListsOwners.Count(x => x.Id == commentAuthorId) == 0) MessageService.Send(new MessageStruct { RecipientId = commentAuthorId, Text = MessageComposer.ComposeCommentNotice(comment.Id, comment.Text), Type = (byte) MessageType.CommentNotice, Date = DateTime.Now }); return comment; }
private void FixupReplyTo(Comment previousValue) { if (previousValue != null && previousValue.Replies.Contains(this)) { previousValue.Replies.Remove(this); } if (ReplyTo != null) { if (!ReplyTo.Replies.Contains(this)) { ReplyTo.Replies.Add(this); } if (ReplyToId != ReplyTo.Id) { ReplyToId = ReplyTo.Id; } } else if (!_settingFK) { ReplyToId = null; } }
private void FixupParentComment(Comment previousValue) { if (previousValue != null && previousValue.ChildComments.Contains(this)) { previousValue.ChildComments.Remove(this); } if (ParentComment != null) { if (!ParentComment.ChildComments.Contains(this)) { ParentComment.ChildComments.Add(this); } if (ParentCommentId != ParentComment.Id) { ParentCommentId = ParentComment.Id; } } else if (!_settingFK) { ParentCommentId = null; } }
public _Comments_CommentViewModel(Comment comment) { if (comment != null) { Id = comment.Id; ContentId = comment.ContentId; ContentUrl = comment.Content.GetUrl(comment); ContentTitle = comment.Content.Title; Text = comment.Text.Split(new[] { "\r\n" }, StringSplitOptions.None); IsHidden = comment.IsHidden; Rating = comment.Rating; DateTime = comment.DateTime; UserId = comment.UserId; UserName = comment.User.FirstName; UserSurname = comment.User.SurName; UserAvatar = ImageService.GetImageUrl<User>(comment.User.Avatar); if (comment.User.AddressId.HasValue) UserGeo = comment.User.Address.City.Title; ChildComments = new List<_Comments_CommentViewModel>(); if (comment.ParentCommentId == null) ChildComments = comment.ChildComments .OrderBy(c => c.DateTime).Select(c => new _Comments_CommentViewModel(c)).OrderBy(x => x.DateTime).ToList(); VisibleChildComments = ChildComments.Count(x => !x.IsHidden); if (comment.ReplyTo != null) ReplyComment = new _Comments_CommentReplyViewModel(comment.ReplyTo); IsReplied = comment.Replies.Count > 0; } }
public _Comments_CommentReplyViewModel(Comment comment) { if (comment != null) { Id = comment.Id; UserId = comment.UserId; UserName = comment.User.FirstName; UserSurname = comment.User.SurName; } }
private void FixupComment(Comment previousValue) { if (previousValue != null && previousValue.Likes.Contains(this)) { previousValue.Likes.Remove(this); } if (Comment != null) { if (!Comment.Likes.Contains(this)) { Comment.Likes.Add(this); } if (CommentId != Comment.Id) { CommentId = Comment.Id; } } else if (!_settingFK) { CommentId = null; } }