예제 #1
0
    protected void btnCheckOut_Click(object sender, EventArgs e)
    {
        string bug = ((TextBox)LoginView1.FindControl("txtBugId")).Text;
        int bugId;

        try
        {
                ITransactionRepository transactionRepo = new TransactionRepository();
                IBugRepository bugRepo = new BugRepository();

                var result = bugRepo.GetBugIdByTitle(bug);

                if (result == 0)
                {
                    Bug newBug = new Bug()
                    {
                        Bug1 = bug

                    };

                    bugRepo.InsertBug(newBug);
                    bugRepo.Save();
                }

                bugId = (int)bugRepo.GetBugIdByTitle(bug);

                //check if bug was not checked out previously (check if there is any transaction for this bug)
                var testCheckout = transactionRepo.GetLastTransactionForBug(bugId);

                //if there is an transaction
                if (testCheckout != null)
                {
                    //check if bug is not checked out now
                    if (testCheckout.StatusId != 8)
                    {
                        //check out bug
                        CheckoutBug(bugId, transactionRepo);

                        ((Label)LoginView1.FindControl("lblAlreadyCheckedOut")).Visible = false;

                        setGridView(gridIdBugsMe, true);
                        setGridView(gridIdBugsOthers, false);
                    }
                    else
                    {
                        ((Label)LoginView1.FindControl("lblAlreadyCheckedOut")).Visible = true;
                    }
                }
                else
                {
                    CheckoutBug(bugId, transactionRepo);

                    ((Label)LoginView1.FindControl("lblAlreadyCheckedOut")).Visible = false;

                    setGridView(gridIdBugsMe, true);
                    setGridView(gridIdBugsOthers, false);
                }
        }
        catch (DataException ex)
        {
            ((Label)LoginView1.FindControl("lblException")).Visible = true;
            ((Label)LoginView1.FindControl("lblException")).Text = "Data not available, please try again later (" + ex.Message + ex.InnerException.Message + ").";
        }
    }