public void Add_Comment(Object s, EventArgs e) { if (Authentication.IsUserAuthenticated) { if (Page.IsValid && (txtsecfield.Text.ToString() == Session["randomStr"].ToString())) { LyricCommentsRepository comment = new LyricCommentsRepository(); comment.ID = (int)Util.Val(Request.QueryString["id"]); comment.UID = UserIdentity.UserID; comment.Author = Util.FormatTextForInput(Request.Form[AUTHOR.UniqueID]); comment.Email = Util.FormatTextForInput(Request.Form[EMAIL.UniqueID]); comment.Comments = Util.FormatTextForInput(Request.Form[COMMENTS.UniqueID]); if (comment.Comments.Length == 0) { lbvalenght.Text = "<br>Lỗi: Lời bình chưa có, hãy đưa vào lời bình của bạn."; lbvalenght.Visible = true; txtsecfield.Text = ""; return; } if (comment.Comments.Length > 350) { lbvalenght.Text = "<br>Lỗi: Lời bình quá dài. Lớn nhất là 350 ký tự."; lbvalenght.Visible = true; txtsecfield.Text = ""; return; } if (comment.Add(comment) != 0) { lbvalenght.Text = "Một lỗi cơ sở dữ liệu trong quá trình sử lý lời bình của bạn."; return; } EmailCommentNotificationToAdministrator(comment.ID, strRName); comment = null; Response.Redirect("commentpostconfirmation.aspx?ReturnURL=" + this.Request.Url.PathAndQuery); } else { lbvalenght.Text = "<br>Mã bảo mật không đúng. Chắc chắn những gì bạn đưa vào là đúng."; lbvalenght.Visible = true; txtsecfield.Text = ""; lblinvalidsecode.Text = "Mã bảo mật không đúng. Chắc chắn những gì bạn đưa vào là đúng."; lblinvalidsecode.Visible = true; } } }
//Handles update comment public void Update_Comments(Object s, EventArgs e) { LyricCommentsRepository comment = new LyricCommentsRepository(); comment.ID = int.Parse(Request.Form["KeyIDs"]); comment.Comments = Request.Form["Comments"]; if (comment.Update(comment) != 0) { JSLiteral.Text = "Error occured while processing your submit."; return; } comment = null; Response.Redirect("confirmcommentupdate.aspx?mode=update&id=" + Request.Form["KeyIDs"]); }
//Handle the delete button click event public void RecipeComments_RowCommand(object sender, GridViewCommandEventArgs e) { if ((e.CommandName == "DeleteComment")) { //Passing multiple command argument separated by comma so we can split it. string[] commandArgsDelete = e.CommandArgument.ToString().Split(new char[] { ',' }); int COMID = int.Parse(commandArgsDelete[0].ToString()); // Get the Comment ID int RecID = int.Parse(commandArgsDelete[1].ToString()); // Get the Lyric ID LyricCommentsRepository comment = new LyricCommentsRepository(); comment.ID = COMID; comment.RECID = RecID; comment.Delete(comment); comment = null; Response.Redirect("confirmcommentupdate.aspx?mode=del&id=" + COMID); } if ((e.CommandName == "EditComment")) { //Passing multiple command argument separated by comma so we can split it. string[] commandArgsEdit = e.CommandArgument.ToString().Split(new char[] { ',' }); int CID = int.Parse(commandArgsEdit[0].ToString()); // Get the Comment ID string strComment = commandArgsEdit[1].ToString(); // Get the Comment Panel1.Visible = true; KeyIDs.Value = CID.ToString(); Comments.Text = strComment; lblheaderform.Text = "Updating Comment #: " + CID; } else { Panel1.Visible = false; } }