/
CheckInSingle.aspx.cs
94 lines (72 loc) · 3.37 KB
/
CheckInSingle.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrackerModel;
public partial class CheckInSingle : System.Web.UI.Page
{
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 btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("~/Default.aspx");
}
protected void btnCheckIn_Click(object sender, EventArgs e)
{
using (CrackerEntities myEntity = new CrackerEntities())
{
ITransactionRepository transactionRepo = new TransactionRepository();
IBugRepository bugRepo = new BugRepository();
string bugName = Request.QueryString.Get("BugID");
var bugId = bugRepo.GetBugIdByTitle(bugName);
Transaction myTransaction = new Transaction
{
BugId = (int)bugId,
ChangedBy = HttpContext.Current.User.Identity.Name,
ChangedOn = DateTime.Now,
StatusId = Int32.Parse(((DropDownList)LoginView1.FindControl("ddlResolution")).SelectedValue),
TimeSpent = Int32.Parse(((TextBox)LoginView1.FindControl("txtTime")).Text),
LanguageId = Int32.Parse(((DropDownList)LoginView1.FindControl("ddlLanguages")).SelectedValue),
Note = HttpUtility.HtmlEncode(((TextBox)LoginView1.FindControl("txtNote")).Text)
};
transactionRepo.InsertTransaction(myTransaction);
transactionRepo.Save();
}
Response.Redirect("~/Default.aspx");
}
}