Example #1
0
        private void dgvComments_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int    commentId = int.Parse(dgvComments.Rows[e.RowIndex].Cells["Comment Id"].Value.ToString());
            int    userId    = service.GetUserIdByCommentId(commentId);
            DbUser user      = service.GetUserByUserName(username)[0];
            int    userId2   = user.UserId;

            if (e.ColumnIndex == 0)
            {
                if (userId == userId2)
                {
                    if (MessageBox.Show("Are you sure You want to delete this comment?", "Confirm",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (service.DeleteComment(commentId) == true)
                        {
                            lblMessage.Text = "Your comment has been successfully deleted";
                            FilldgvComments();
                        }
                        else
                        {
                            MessageBox.Show("Something went wrong, please try again", "Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                            lblMessage.Text = "";
                        }
                    }
                }
                else
                {
                    MessageBox.Show("You can only delete your own comments", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    lblMessage.Text = "";
                }
            }
        }
Example #2
0
        protected void gvComments_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int rowIndex = e.RowIndex;

            jobId = int.Parse(Session["jobId"].ToString());
            dt    = ToDataTable <DbComments>(service.ViewComments(jobId).ToList());
            DataRow dr        = dt.Rows[rowIndex];
            int     commentId = (int)dr["CommentId"];
            int     userId    = service.GetUserIdByCommentId(commentId);
            int     userId2   = int.Parse(Session["userid"].ToString());

            if (userId != userId2)
            {
                lblError.Text   = "You can only delete your own comments";
                lblSuccess.Text = "";
            }
            else
            {
                if (service.DeleteComment(commentId) == true)
                {
                    lblSuccess.Text = "Your comment has been successfully deleted";
                    lblError.Text   = "";
                    BindCommentData(jobId);
                }
                else
                {
                    lblError.Text   = "Something went wrong! Please try again";
                    lblSuccess.Text = "";
                }
            }
        }