/
UpdateAll.aspx.cs
50 lines (44 loc) · 1.42 KB
/
UpdateAll.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class UpdateAll : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinqDataSource1_Deleting(object sender, LinqDataSourceDeleteEventArgs e)
{
lblError.Visible = true;
PersonInfo p = e.OriginalObject as PersonInfo;
if (p.PersonID == 0)
{
e.Cancel = true;
return;
}
if (p.SpouseID != null && p.SpouseID > 0)
{
e.Cancel = true;
lblError.Text = "Remove Spouse of the person before deleting.";
return;
}
using (MyFamilyDatabaseDataContext db = new MyFamilyDatabaseDataContext())
{
PersonInfo spouse = db.PersonInfos.Where(o => o.SpouseID == p.PersonID).FirstOrDefault();
if (spouse != null && spouse.PersonID != 0)
{
e.Cancel = true;
lblError.Text = "Person is already marked as Spouse for " + spouse.PersonID + ", update Person first.";
return;
}
if (db.PersonInfos.Where(c => c.FatherID == p.PersonID).Count() > 0)
{
e.Cancel = true;
lblError.Text = "Person is already father.";
return;
}
}
}
}