protected void Page_Load(object sender, EventArgs e) { string bugName = Request.QueryString.Get("BugID"); string checkedOutBy; DateTime changedOn; using (CrackerEntities myEntity = new CrackerEntities()) { ITransactionRepository transactionRepo = new TransactionRepository(); //Verify that the bug we are going to check in can be checked in //Get bug ID var result = (from bug in myEntity.Bugs where bug.Bug1 == bugName select bug).SingleOrDefault(); if (result != null) { var check = transactionRepo.GetLastTransactionForBug(result.Id); changedOn = Convert.ToDateTime(check.ChangedOn); checkedOutBy = Convert.ToString(check.ChangedBy); if (checkedOutBy != HttpContext.Current.User.Identity.Name) { ((Label)LoginView1.FindControl("lblWarning")).ForeColor = System.Drawing.Color.Red; ((Label)LoginView1.FindControl("lblWarning")).Text = "You're about to check in a bug that was not checked out by you!"; } //get how long has the bug been checked out ((TextBox)LoginView1.FindControl("txtTime")).Text = Math.Round(DateTime.Now.Subtract(changedOn).TotalMinutes, 0).ToString(); ((Label)LoginView1.FindControl("lblBugId")).Text = bugName; } else { ((Label)LoginView1.FindControl("lblBugId")).ForeColor = System.Drawing.Color.Red; ((Label)LoginView1.FindControl("lblBugId")).Text = bugName + " does not exist!"; ((Button)LoginView1.FindControl("btnCheckIn")).Enabled = false; } } }
protected void Page_Load(object sender, EventArgs e) { string bugName = Request.QueryString.Get("BugID"); ((Label)LoginView1.FindControl("lblBugID")).Text = bugName; string checkedOutBy; DateTime changedOn; string status; ITransactionRepository transactionRepo = new TransactionRepository(); IBugRepository bugRepo = new BugRepository(); //Verify that the bug we are going to check in can be checked in //Get bug ID var result = bugRepo.GetBugIdByTitle(bugName); if (result != null) { //check if the bug is checked out & if it's checked by current user var check = transactionRepo.GetLastTransactionForBug((int)result); status = Convert.ToString(check.Status.StatusName); changedOn = Convert.ToDateTime(check.ChangedOn); checkedOutBy = Convert.ToString(check.ChangedBy); if (checkedOutBy != HttpContext.Current.User.Identity.Name) { ((Label)LoginView1.FindControl("lblWarning")).ForeColor = System.Drawing.Color.Red; ((Label)LoginView1.FindControl("lblWarning")).Text = "You're about to undo a bug that was not checked out by you!"; } //get how long has the bug been checked out ((TextBox)LoginView1.FindControl("txtTime")).Text = Math.Round(DateTime.Now.Subtract(changedOn).TotalMinutes, 0).ToString(); ((Label)LoginView1.FindControl("lblBugID")).Text = bugName; } else { ((Label)LoginView1.FindControl("lblBugID")).ForeColor = System.Drawing.Color.Red; ((Label)LoginView1.FindControl("lblBugID")).Text = bugName + " does not exist!"; ((Button)LoginView1.FindControl("btnUNdo")).Enabled = false; } }
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 + ")."; } }