public IActionResult Post([FromBody] ArticleCommentModel model) { try { if (ModelState.IsValid) { var entity = new ArticleComment { CommentText = model.CommentText, ArticleId = model.ArticleId, IsApproved = model.IsApproved }; _articleService.AddArticleComment(entity); return(Ok()); } return(new BadRequestResult()); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public UserOperation GetUserOperation() { UserOperation op = new UserOperation(); switch (this._operationOption) { case UserOperationEnum.Read: case UserOperationEnum.Share: case UserOperationEnum.Favorite: op.ArticleId = Convert.ToInt32(this.actionParams["Id"]); op.CreateDateTime = DateTime.Now; op.DeviceId = this.actionParams.ContainsKey("DeviceId") && !string.IsNullOrEmpty((string)this.actionParams["DeviceId"]) ? Guid.Parse(this.actionParams["DeviceId"].ToString()) : Guid.Empty; op.Operation = this._operationOption.ToString(); op.UserId = this.actionParams.ContainsKey("userId") && !string.IsNullOrEmpty(this.actionParams["userId"]?.ToString()) ? Guid.Parse(this.actionParams["userId"].ToString()) : Guid.Empty; break; case UserOperationEnum.Comment: ArticleCommentModel comment = this.actionParams["acm"] as ArticleCommentModel; op.ArticleId = comment.PKID; op.CreateDateTime = DateTime.Now; op.DeviceId = Guid.Empty; op.Operation = this._operationOption.ToString(); op.UserId = Guid.Parse(comment.UserID); break; } return(op); }
public IActionResult Put(int id, [FromBody] ArticleCommentModel model) { try { if (ModelState.IsValid) { var entity = _articleService.GetArticleCommentById(id); if (entity == null) { return(new NotFoundResult()); } entity.CommentText = model.CommentText; entity.ArticleId = model.ArticleId; entity.IsApproved = model.IsApproved; _articleService.UpdateArticleComment(entity); return(Ok()); } return(new BadRequestResult()); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
/// <summary> /// 创建评论 /// </summary> public bool CreateArticleComment(ArticleCommentModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ArticleComment("); strSql.Append("CommentID,ArticleID,CustomerID,ContentDesc,DataState,CreateDate)"); strSql.Append(" values ("); strSql.Append("@CommentID,@ArticleID,@CustomerID,@ContentDesc,@DataState,@CreateDate)"); SqlParameter[] parameters = { new SqlParameter("@CommentID", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@ArticleID", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@CustomerID", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@ContentDesc", SqlDbType.VarChar, -1), new SqlParameter("@DataState", SqlDbType.Int, 4), new SqlParameter("@CreateDate", SqlDbType.DateTime) }; parameters[0].Value = Guid.NewGuid(); parameters[1].Value = model.ArticleID; parameters[2].Value = model.CustomerID; parameters[3].Value = model.ContentDesc; parameters[4].Value = 0; parameters[5].Value = DateTime.Now; int rows = DBHelper.ExecuteCommand(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public IActionResult Get(int id) { try { var entity = _articleService.GetArticleCommentById(id); if (entity == null) { return(new NotFoundResult()); } var model = new ArticleCommentModel { Id = entity.Id, CommentText = entity.CommentText, ArticleId = entity.ArticleId, IsApproved = entity.IsApproved }; return(new ObjectResult(model)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public void Update(int articleCommentId, ArticleCommentModel articleComment) { var result = _context.ArticleComments.SingleOrDefault(x => x.ArticleCommentId == articleCommentId); if (result != null) { result.Text = articleComment.Text; _context.SaveChanges(); } }
public void Delete(int articleCommentId, ArticleCommentModel articleComment) { var result = _context.ArticleComments.SingleOrDefault(x => x.ArticleCommentId == articleCommentId); if (result != null) { _context.ArticleComments.Remove(result); _context.SaveChanges(); } }
public async Task <IActionResult> Post(int?id) { ArticleCommentModel acm = new ArticleCommentModel(); acm.article = GetArticleModel(id); if (acm.article.Category != "Question") { acm.Comments = GetCommentsModel(id); acm.article.Pagerarticle = new ArticlePager(acm.article.ID); return(View(acm)); } else { return(RedirectToAction("Post", "Answers", new { id = id })); } }
protected void btnPost_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtContent.Text)) { Response.Write("<Script language=javascript>alert('请输入评论内容!');</script>"); } else { ShortArticleService articleService = new ShortArticleService(); CustomerModel customer1 = Session["UserInfo"] as CustomerModel; ArticleCommentModel model = new ArticleCommentModel(); model.ArticleID = Guid.Parse(Request.QueryString["ArticleID"]); model.ContentDesc = txtContent.Text.Trim(); model.CustomerID = customer1.CustomerID; articleService.CreateArticleComment(model); Response.Redirect("ShortArticle.aspx?ArticleID=" + Request.QueryString["ArticleID"]); } }
public void PostComment(AccessToken token, string blogApp, int id, string content) { try { var url = string.Format(ApiUtils.ArticleCommentAdd, blogApp, id); OkHttpUtils.Instance(token).Post(url, content, async(call, response) => { var code = response.Code(); var body = await response.Body().StringAsync(); if (code == (int)System.Net.HttpStatusCode.OK) { var user = await SQLiteUtils.Instance().QueryUser(); ArticleCommentModel article = new ArticleCommentModel(); article.Author = user.DisplayName; article.AuthorUrl = user.Avatar; article.FaceUrl = user.Face; article.Body = content; article.DateAdded = DateTime.Now; article.Floor = 0; article.Id = 0; commentView.PostCommentSuccess(article); } else { try { var error = JsonConvert.DeserializeObject <ErrorMessage>(body); commentView.PostCommentFail(error.Message); } catch (Exception e) { commentView.PostCommentFail(e.Message); } } }, (call, ex) => { commentView.PostCommentFail(ex.Message); }); } catch (Exception e) { commentView.PostCommentFail(e.Message); } }
public ActionResult AddComment(int id, ArticleCommentModel comment) { comment.ArticleID = id; comment.Date = DateTime.Now; tblComments dbComment = new tblComments() { Comment = comment.Text, Date = comment.Date, ArticleID = comment.ArticleID, UserID = 1 }; var comments = _commentsManager.AddCommentToArticleById(id, dbComment).OrderByDescending(n => n.Date).ToList <tblComments>(); ViewBag.Comments = comments; ViewBag.ArticleID = id; return(View("CommentPartial")); }
public void PostCommentSuccess(ArticleCommentModel comment) { handler.Post(() => { txtContent.Enabled = true; txtContent.Text = ""; proLoading.Visibility = ViewStates.Gone; btnComment.Visibility = ViewStates.Visible; var data = adapter.GetData(); if (data.Count > 0) { comment.Floor = data[data.Count - 1].Floor + 1; } else { comment.Floor = 1; } adapter.AddData(comment); Toast.MakeText(this, Resources.GetString(Resource.String.comment_success), ToastLength.Short).Show(); }); }
public ActionResult Delete(int id, ArticleCommentModel articleComment) { _articleCommentRepository.Delete(id, articleComment); return(RedirectToAction(nameof(Index))); }
public void Add(int position, ArticleCommentModel item) { List.Insert(position, item); NotifyItemInserted(position); }
public void Add(ArticleCommentModel articleComment) { articleComment.DateOfPublish = DateTime.Now; _context.ArticleComments.Add(articleComment); _context.SaveChanges(); }
/// <summary> /// 添加评论 /// </summary> /// <param name="ac"></param> /// <returns></returns> public static int AddComment(ArticleCommentModel ac) { return(Articles.AddComment(ac)); }
/// <summary> /// 添加评论 /// </summary> /// <param name="ac"></param> /// <returns></returns> public static int AddComment(ArticleCommentModel ac) { using (var cmd = new SqlCommand(@"INSERT INTO Marketing..tbl_Comment (PKID, Category, Title, PhoneNum, UserID, UserHead, CommentContent, CommentTime, AuditStatus, AuditTime, UserName, UserGrade, RealName, ParentID, Sex, Type ) VALUES (@PKID, @Category, @Title, @PhoneNum, @UserID, @UserHead, @CommentContent, @CommentTime, 0, @AuditTime, @UserName, @UserGrade, @RealName, @ParentID, @Sex, 0 );" )) { cmd.CommandType = CommandType.Text; #region AddParameters cmd.Parameters.AddWithValue("@PKID", ac.PKID); cmd.Parameters.AddWithValue("@Category", ac.Category); cmd.Parameters.AddWithValue("@Title", ac.Title); cmd.Parameters.AddWithValue("@PhoneNum", ac.PhoneNum); cmd.Parameters.AddWithValue("@UserID", ac.UserID); cmd.Parameters.AddWithValue("@UserHead", ac.UserHead); cmd.Parameters.AddWithValue("@CommentContent", ac.CommentContent); cmd.Parameters.AddWithValue("@CommentTime", DateTime.Now); cmd.Parameters.AddWithValue("@AuditStatus", ac.AuditStatus); cmd.Parameters.AddWithValue("@AuditTime", DateTime.Now); cmd.Parameters.AddWithValue("@UserName", ac.UserName); cmd.Parameters.AddWithValue("@UserGrade", ac.UserGrade); cmd.Parameters.AddWithValue("@RealName", ac.RealName); cmd.Parameters.AddWithValue("@ParentID", ac.ParentID); cmd.Parameters.AddWithValue("@Sex", ac.Sex); #endregion return(DbHelper.ExecuteNonQuery(cmd)); } }