public void Invoke(HttpSessionState session, DataInputStream input) { _result = HttpProcessor.GetClient<CommentServiceSoapClient>(session).GetComment( input.ReadString(), input.ReadString(), input.ReadInt32()); }
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); }
public IHttpActionResult Comments(WebComment comment) { try { if (!ModelState.IsValid) { return(BadRequest("Passed information isn't valid.")); } var rc = Mapper.MapComment(comment); if (rc != null) { var da = new DataAccess(); da.AddComment(rc, comment.Author, comment.ArticleId); logger.Info("Added comment " + comment.CommentId + " from author " + comment.Author + " on article " + comment.ArticleId); return(Ok()); } else { throw new NotImplementedException(); } } catch (Exception ex) { logger.Error(ex, "Attempt to add comment by author " + comment.Author + "on article " + comment.ArticleId + " failed: " + ex.Message); return(BadRequest("Something went wrong while saving comment.")); } }
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 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); }
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); }
/// <summary> /// 获得一条评论 /// </summary> /// <param name="webComment">当前评论对象</param> /// <param name="commentId">设置当前评论列表---div里的id,使得每个div都不重复</param> /// <returns></returns> private static string GetOneWebCommentHtml(WebComment webComment, int commentId) { StringBuilder sb = new StringBuilder(); if (webComment is null) { return(""); } int UserId = webComment.UserId; User u = m_UserDal.GetModel(webComment.UserId); string HeadPic = u.HeadPic; string UserName = u.UserName; string CommentTitle = webComment.CommentTitle; string CommentText = webComment.CommentText; DateTime CreatedTime = webComment.CreatedTime; #region 网页拼凑 //当前帖子讨论数 int count = m_WebCommentReplyDAL.GetCount(string.Format("WebCommentId={0}", webComment.WebCommentId)); sb.Append(string.Format(@"<div class=""commentItem"" id=""commentId_{5}""> <div class=""itemLeft""> <img src = ""../upfile/HeadPic/{0}"" /> </div> <div class=""itemCenter""> <div class=""itemCenter_1""> <a href=""CommentReply.aspx?WebCommentId={6}"" target=""_blank"">{1}</a> </div> <div class=""itemCenter_2""> <div class=""commentUser"">{2}</div> <div class=""publishTime""> 发表于: {3} </div> </div> <div class=""itemCenter_3"" id=""commentImgId_{5}""> {4} </div> </div> <div class=""itemRight""> <span class=""blue-color"">{7}</span> <p>讨论中(回帖数)</p> </div> </div>", HeadPic, CommentTitle, UserName, CreatedTime, CommentText, commentId, webComment.WebCommentId, count)); #endregion return(sb.ToString()); }
public static void WriteGetCommentResult(this DataOutputStream output, WebComment value) { if (value == null) { throw new ArgumentNullException("value"); } output.WriteInt32(value.ID); output.WriteInt32(value.ObjectID); output.WriteString(value.Nickname); output.WriteString(value.Text); output.WriteDateTime(value.DTCreated.ToDateTime()); output.WriteInt32(value.InReplyToCommentID); output.WriteInt32(value.ParentCommentID); output.WriteInt32(value.CommentType); }
// Get: Change to New Comment View public ActionResult Comment(int articleId) { try { var comment = new WebComment() { Author = Session["UserName"].ToString(), ArticleId = articleId }; return(View(comment)); } catch (Exception ex) { // Log error here logger.Error(ex.Message); return(View("Error")); } }
// Map the WebComment to DAL.Comment public static Comment MapComment(WebComment wc) { try { var c = new Comment() { Comment1 = wc.Comment, CommentedAt = wc.CommentedAt, Modified = wc.CommentedAt, Active = true }; return(c); } catch (Exception ex) { logger.Error(ex, "Attempt to map webcomment to comment failed: " + ex.Message); return(null); // return nothing to the caller } }
public async Task <ActionResult> Comment(WebComment model) { try { if (!ModelState.IsValid) { throw new Exception("Enter information isn't valid."); } // Let's set the author and CommentedAt properties now model.Author = Session["UserName"].ToString(); model.CommentedAt = DateTime.Now; HttpRequestMessage requestMessage = CreateRequestToService(HttpMethod.Post, "api/Data/Add"); requestMessage.Content = new ObjectContent <WebComment>(model, new JsonMediaTypeFormatter()); HttpResponseMessage apiResponse; try { apiResponse = await client.SendAsync(requestMessage); if (!apiResponse.IsSuccessStatusCode) { throw new Exception("Request failed with following error: " + apiResponse.StatusCode); } } catch (Exception ex) { // Log error here logger.Error(ex.Message); return(View("Error")); } return(RedirectToAction("Index")); // For now just go back to the main page } catch (Exception ex) { // Log error here logger.Error(ex.Message); return(View("Error")); } }
// Map a DAL.Comment object to a WebComment object public static WebComment MapComment(Comment comment, int articleId, int commentId) { try { var da = new DataAccess(); var author = da.GetAuthor(articleId, commentId); var c = new WebComment() { Comment = comment.Comment1, Author = author, CommentedAt = comment.CommentedAt, ArticleId = articleId, CommentId = commentId }; return(c); } catch (Exception ex) { logger.Error(ex, "Attempt to map comment to webcomment failed: " + ex.Message); return(null); // return nothing to the caller; Maybe I shouldn't return null? } }
public string AddComment() { string title = context.Request.Form["title"].ToString(); string text = context.Request.Form["text"].ToString(); //过滤html标签再判断是否为空 if (CRegex.FilterHTML(text) == "") { rm.Info = "内容不能为空"; return(jss.Serialize(rm)); } else if (CRegex.FilterHTML(text).Length > 500 || CRegex.FilterHTML(text).Length < 6) { rm.Info = "问题内容长度在6~500之间"; return(jss.Serialize(rm)); } else { string strIP = WebHelp.GetIP(); User user = UserDal.CurrentUser();//获取当前登陆用户 List <dbParam> list = new List <dbParam>() { new dbParam() { ParamName = "@ClientIP", ParamValue = strIP }, new dbParam() { ParamName = "@UserId", ParamValue = user.UserId } }; #region 一IP,同一当前日期(年月日),可以确定当天评论次数。 List <WebComment> wList = WebCommentDAL.m_WebCommentDal.GetList(" ClientIP=@ClientIP and UserId=@UserId", list); int count = 0; if (wList.Count == 0) { count = 0; } else { string DateCurrent = string.Format("{0:D}", DateTime.Now);//设置当前日期(年-月-日) foreach (var w in wList) { if (DateCurrent == string.Format("{0:D}", w.CreatedTime)) { count++; } } } #endregion //同一用户不能一天超过三次留言 if (count >= 3) { rm.Info = "一天最多只能发帖三次"; jss.Serialize(rm); } else { if (user.Type < 0) { rm.Info = "只有已登录用户才能发帖"; jss.Serialize(rm); } else { WebComment webCom = new WebComment(); webCom.CommentTitle = title; webCom.CommentText = text; webCom.CreatedTime = DateTime.Now; webCom.ClientIP = WebHelp.GetIP(); webCom.UserId = user.UserId; WebCommentDAL.m_WebCommentDal.Add(webCom); rm.Success = true; rm.Info = "提交成功"; } } } return(jss.Serialize(rm)); }
public static void WriteGetCommentsResult(this DataOutputStream output, WebComment[] value) { if (value == null) throw new ArgumentNullException("value"); output.WriteInt32(value.Length); foreach (var item in value) output.WriteGetCommentResult(item); }
public static void WriteGetCommentResult(this DataOutputStream output, WebComment value) { if (value == null) throw new ArgumentNullException("value"); output.WriteInt32(value.ID); output.WriteInt32(value.ObjectID); output.WriteString(value.Nickname); output.WriteString(value.Text); output.WriteDateTime(value.DTCreated.ToDateTime()); output.WriteInt32(value.InReplyToCommentID); output.WriteInt32(value.ParentCommentID); output.WriteInt32(value.CommentType); }
private static void UpdateComment(data.Comment commentToUpdate, WebComment comment) { commentToUpdate.Text = HttpUtility.HtmlEncode(comment.Text); commentToUpdate.Save(); }