protected void btnWriteComment_Click(object sender, EventArgs e) { ArticleCommentBase comment = new ArticleCommentBase(); comment.ArticleId = Convert.ToInt32(Request["Id"]); // 부모글 comment.Name = txtName.Text; // 이름 comment.Password = txtPassword.Text; // 암호 comment.Opinion = txtOpinion.Text; // 댓글 // 데이터 입력 _repository.AddComment(comment); Response.Redirect($"{Request.ServerVariables["SCRIPT_NAME"]}?Id={Request["Id"]}"); }
/// <summary> /// 특정 게시물에 댓글 추가 /// </summary> public void AddComment(ArticleCommentBase model) { // 파라미터 추가 var parameters = new DynamicParameters(); parameters.Add( "@ArticleId", value: model.ArticleId, dbType: DbType.Int32); parameters.Add( "@Name", value: model.Name, dbType: DbType.String); parameters.Add( "@Opinion", value: model.Opinion, dbType: DbType.String); parameters.Add( "@Password", value: model.Password, dbType: DbType.String); string sql = @" Insert Into CongressesComments (ArticleId, Name, Opinion, Password) Values(@ArticleId, @Name, @Opinion, @Password); Update Congresses Set CommentCount = CommentCount + 1 Where Id = @ArticleId "; db.Execute(sql, parameters, commandType: CommandType.Text); }