/
Assignment.aspx.cs
110 lines (96 loc) · 3.64 KB
/
Assignment.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Windchime
{
public partial class Assignment1 : System.Web.UI.Page
{
private int? id
{
get
{
return (int?)this.ViewState["ID"];
}
set
{
this.ViewState["ID"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
return;
}
using (WindchimeEntities wce = new WindchimeEntities())
{
Author_lst.DataTextField = "Name";
Author_lst.DataValueField = "ID";
Author_lst.DataSource = from User u in wce.CreatorSet.OfType<User>()
select new
{
Name = u.FirstName + " " + u.LastName,
ID = u.CreatorID
};
Author_lst.DataBind();
if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
{
id = int.Parse(Request.QueryString["ID"]);
Assignment assgn = (from Assignment a in wce.PermissionableEntities.OfType<Assignment>()
where a.EntityID == id
select a).FirstOrDefault();
if (assgn == null)
throw new ArgumentException("Invalid ID specified as parameter.");
Location_box.Text = assgn.Location;
Completed_chk.Checked = (assgn.CompletedDate != null);
DueDate_box.Text = assgn.DueDate.ToString();
Name_box.Text = assgn.Name;
Summary_box.Text = assgn.Summary;
}
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Save_btn.Click += new EventHandler(Save_Click);
SaveQuit_btn.Click += new EventHandler(SaveQuit_Click);
}
void SaveQuit_Click(object sender, EventArgs e)
{
Save_Click(sender, e);
Response.Redirect("~/Assignments.aspx", false);
}
void Save_Click(object sender, EventArgs e)
{
Assignment assgn = null;
using (WindchimeEntities wce = new WindchimeEntities())
{
if (id != null)
{
assgn = (from Assignment a in wce.PermissionableEntities.OfType<Assignment>()
where a.EntityID == id
select a).FirstOrDefault();
}
if (assgn == null)
{
assgn = new Assignment();
wce.AddToPermissionableEntities(assgn);
}
assgn.Summary = Summary_box.Text;
assgn.Name = Name_box.Text;
assgn.DueDate = DateTime.Parse(DueDate_box.Text);
assgn.Location = Location_box.Text;
if (Completed_chk.Checked && assgn.CompletedDate == null)
assgn.CompletedDate = DateTime.Now;
else if (!Completed_chk.Checked)
assgn.CompletedDate = null;
wce.SaveChanges();
wce.Refresh(System.Data.Objects.RefreshMode.StoreWins, assgn);
id = assgn.EntityID;
}
}
}
}