Example #1
0
        protected void ButtonDeleteIssue_Click(object sender, EventArgs e)
        {
            try
            {
                // checks
                CheckForDangerousInput();
                var issueKey = TextBox_Delete_IssueKey.Text.Trim();

                if (!Issues.IsValidIssue(issueKey))
                {
                    throw new ApplicationException("The IssueKey is not valid.");
                }

                var icount = Questions.CountByIssueKey(issueKey);
                if (icount > 0)
                {
                    throw new ApplicationException(
                              $"There are {icount} questions. These need to be reassigned before" +
                              " this issue can be deleted.");
                }

                var qcount = Answers.CountByQuestionKey(TextBox_Delete_QuestionKey.Text.Trim());
                if (qcount > 0)
                {
                    throw new ApplicationException(
                              $"There are {qcount} answers. These need to be reassigned or deleted" +
                              " before this question can be deleted.");
                }

                Issues.DeleteByIssueKey(issueKey);

                TextBox_Delete_IssueKey.Text = Empty;

                RenumberIssues();

                //CreateIssuesReport();

                // Reset Tables Not Visible
                Table_Question_Edit.Visible    = false;
                Table_Question_Add.Visible     = false;
                Table_Question.Visible         = false;
                Table_Delete_Question.Visible  = false;
                Table_Questions_Report.Visible = false;


                Table_Issue_Edit.Visible = false;
                Table_Issue_Add.Visible  = false;

                Msg.Text = Ok("The issue has been deleted.");
            }
            catch (Exception ex)
            {
                Msg.Text = Fail(ex.Message);
                LogAdminError(ex);
            }
        }
Example #2
0
        // Buttons
        //Issues
        protected void ButtonAddIssue_Click(object sender, EventArgs e)
        {
            try
            {
                CheckForDangerousInput();

                if (!Table_Issue_Add.Visible)
                {
                    // 1st Step in Adding an Issue

                    //Only Add Issue Table Visible
                    Table_Issue_Add.Visible  = true;
                    Table_Issue_Edit.Visible = false;

                    TextBox_Issue_Description_Add.Text = Empty;
                    TextBox_Issue_Order_Add.Text       = Empty;

                    Msg.Text =
                        Message(
                            "To complete the add, enter the issue description and optional order." +
                            " Then click the 'Add an Issue' Button.");
                }
                else
                {
                    // 2nd Step - Complete the Issue Addition
                    var descripton = TextBox_Issue_Description_Add.Text.Trim();
                    var order      = TextBox_Issue_Order_Add.Text.Trim();

                    // Checks
                    if (descripton == Empty)
                    {
                        throw new ApplicationException("The Description Textbox is empty.");
                    }
                    if (!IsNullOrEmpty(order) && !order.IsValidInteger())
                    {
                        throw new ApplicationException(
                                  "The Order Textbox needs to be an integer.");
                    }
                    if (descripton.Length > 40)
                    {
                        var tooLongBy = descripton.Length - 40;
                        throw new ApplicationException(
                                  "When adding a new issue, the Issue description must be 40 characters" +
                                  $" or less. You need to shorten by {tooLongBy} characters");
                    }


                    // Make IssueKey and check its unique
                    var issueKey = MakeIssueKey(Empty, Empty, descripton.SimpleRecase());

                    if (Issues.IsValidIssue(issueKey))
                    {
                        throw new ApplicationException("Issue ({descripton}) already exists");
                    }
                    _IssueKey = issueKey;

                    // Issue Order
                    var issueOrder = order != Empty
            ? Convert.ToInt16(order)
            : 1;

                    // Add the Issue
                    Issues.Insert(_IssueKey, issueOrder, descripton, GetIssueLevelInIssueKey(_IssueKey),
                                  StateCode, CountyCode, Empty, false, false);

                    RenumberIssues();

                    //CreateIssuesReport();

                    //  Edit Issue Table and load
                    Table_Issue_Add.Visible        = false;
                    Table_Issue_Edit.Visible       = true;
                    TextBox_Issue_Description.Text = Issue_Desc(_IssueKey);
                    TextBox_Issue_Order.Text       =
                        Issues.GetIssueOrder(_IssueKey, 0).ToString(CultureInfo.InvariantCulture);

                    Msg.Text = Ok("The issue has been added and is in the report below.");
                }
            }
            catch (Exception ex)
            {
                Msg.Text = Fail(ex.Message);
                LogAdminError(ex);
            }
        }