public Int32 AddComment(String nickname, String password, WebComment newComment) { if (String.IsNullOrEmpty(nickname)) throw new ArgumentNullException("nickname"); if (String.IsNullOrEmpty(password)) throw new ArgumentNullException("password"); if (newComment == null) throw new ArgumentNullException("newComment"); var member = Member.GetMemberViaNicknamePassword(nickname, password); if (!Enum.IsDefined(typeof(CommentType), newComment.CommentType)) throw new ArgumentException(String.Format(Resources.Argument_InvalidCommentType, newComment.CommentType)); var comment = CreateComment(newComment, member); MakeFriends(comment); MarkAsFovorite(comment); return comment.CommentID; }
private static data.Comment CreateComment(WebComment comment, Member member) { var inReplyToCommentID = comment.InReplyToCommentID; var inReplyToComment = inReplyToCommentID == 0 ? null : data.Comment.GetComment(inReplyToCommentID); var result = new data.Comment() { ObjectID = comment.ObjectID, MemberIDFrom = member.MemberID, Text = HttpUtility.HtmlEncode(comment.Text), DTCreated = DateTime.Now, IsDeleted = false, CommentType = comment.CommentType, WebCommentID = UniqueID.NewWebID(), Path = inReplyToComment == null ? "/" : String.Format("/{0}/", inReplyToComment.InReplyToCommentID), SentFromMobile = 1 }; result.Save(); result.ThreadNo = inReplyToComment == null ? result.CommentID : inReplyToComment.ThreadNo; result.InReplyToCommentID = inReplyToCommentID == 0 ? result.CommentID : inReplyToCommentID; result.Save(); try { IncrementCommentCount((CommentType)comment.CommentType, comment.ObjectID); } catch { } return result; }
public WebComment[] GetComments(String nickname, String password, Int32 objectID, Int32 lastCommentID, Int32 commentType) { var comments = data.Comment.GetCommentByObjectIDWithJoin(objectID, (CommentType)commentType); var commentsLength = comments.Length; var result = new WebComment[commentsLength]; for (var i = 0; i < commentsLength; i++) result[i] = CreateComment(comments[i]); return result; }
private static void UpdateComment(data.Comment commentToUpdate, WebComment comment) { commentToUpdate.Text = HttpUtility.HtmlEncode(comment.Text); commentToUpdate.Save(); }
public void EditComment(String nickname, String password, WebComment editedComment) { if (String.IsNullOrEmpty(nickname)) throw new ArgumentNullException("nickname"); if (String.IsNullOrEmpty(password)) throw new ArgumentNullException("password"); if (editedComment == null) throw new ArgumentNullException("editedComment"); var member = Member.GetMemberViaNicknamePassword(nickname, password); if (!Enum.IsDefined(typeof(CommentType), editedComment.CommentType)) throw new ArgumentException(String.Format(Resources.Argument_InvalidCommentType, editedComment.CommentType)); var comment = new data.Comment(editedComment.ID); if (comment.MemberIDFrom != member.MemberID) throw new ArgumentException(Resources.Argument_InvalidCommentEditor); UpdateComment(comment, editedComment); }