forked from ucsbfinaid/Financial-Aid-Estimator-.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AidEstimationValidator.Simple.cs
456 lines (370 loc) · 17.3 KB
/
AidEstimationValidator.Simple.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
using System;
using System.Linq;
using Ucsb.Sa.FinAid.AidEstimation.EfcCalculation;
using Ucsb.Sa.FinAid.AidEstimation.EfcCalculation.Arguments;
namespace Ucsb.Sa.FinAid.AidEstimation.Utility
{
public partial class AidEstimationValidator
{
public DependentEfcCalculatorArguments ValidateSimpleDependentEfcCalculatorArguments(RawSimpleDependentEfcCalculatorArguments args)
{
if (args == null)
{
throw new ArgumentException("No raw arguments provided");
}
// Marital Status
MaritalStatus maritalStatus =
_validator.ValidateMaritalStatus(
args.MaritalStatus,
LabelParentMaritalStatus,
ParamMaritalStatus);
// Parent Income
double parentIncome =
_validator.ValidatePositiveMoneyValue(
args.ParentIncome,
LabelParentIncome,
ParamParentIncome);
// Parent Other Income
double parentOtherIncome =
_validator.ValidatePositiveMoneyValue(
args.ParentOtherIncome,
LabelParentOtherIncome,
ParamParentOtherIncome);
// Parent Income Earned By
IncomeEarnedBy incomeEarnedBy =
_validator.ValidateIncomeEarnedBy(
args.ParentIncomeEarnedBy,
LabelParentIncomeEarnedBy,
ParamParentIncomeEarnedBy);
// CHECK: If Single/Separated/Divorced, "Parent Income Earned By" can not be "Both"
if (maritalStatus == MaritalStatus.SingleSeparatedDivorced && incomeEarnedBy == IncomeEarnedBy.Both)
{
_validator.Errors.Add(new ValidationError(ParamParentIncomeEarnedBy,
String.Format(@"{0} was ""Single/Separated/Divorced"", but {1} was marked as earned by both parents",
LabelParentMaritalStatus, LabelParentIncomeEarnedBy)));
}
// CHECK: If "Parent Income Earned By" is "None", then "Parent Income" must be 0
if (incomeEarnedBy == IncomeEarnedBy.None && parentIncome > 0)
{
_validator.Errors.Add(new ValidationError(ParamParentIncome,
String.Format(@"{0} was marked as earned by neither parents, but {1} was greater than 0",
LabelParentIncomeEarnedBy, LabelParentIncome)));
}
// Parent Income Tax Paid
double parentIncomeTaxPaid =
_validator.ValidatePositiveMoneyValue(
args.ParentIncomeTax,
LabelParentIncomeTax,
ParamParentIncomeTax);
// Parent Assets
double parentAssets =
_validator.ValidatePositiveMoneyValue(
args.ParentAssets,
LabelParentAssets,
ParamParentAssets);
// Student Income
double studentIncome =
_validator.ValidatePositiveMoneyValue(
args.StudentIncome,
LabelStudentIncome,
ParamStudentIncome);
// Student Other Income
double studentOtherIncome =
_validator.ValidatePositiveMoneyValue(
args.StudentOtherIncome,
LabelStudentOtherIncome,
ParamStudentOtherIncome);
// Student Income Tax Paid
double studentIncomeTaxPaid =
_validator.ValidatePositiveMoneyValue(
args.StudentIncomeTax,
LabelStudentIncomeTax,
ParamStudentIncomeTax);
// Student Assets
double studentAssets =
_validator.ValidatePositiveMoneyValue(
args.StudentAssets,
LabelStudentAssets,
ParamStudentAssets);
// Number in Household
int numberInHousehold =
_validator.ValidateNonZeroInteger(
args.NumberInHousehold,
LabelNumInHousehold,
ParamNumInHousehold);
// Number in College
int numberInCollege =
_validator.ValidateNonZeroInteger(
args.NumberInCollege,
LabelNumInCollege,
ParamNumInCollege);
// CHECK: Number in Household must be greater than or equal to Number in College
if (numberInCollege > numberInHousehold)
{
_validator.Errors.Add(new ValidationError(ParamNumInCollege,
String.Format(@"{0} must be less than or equal to {1}",
LabelNumInCollege, LabelNumInHousehold)));
}
// State of Residency
UnitedStatesStateOrTerritory stateOfResidency =
_validator.ValidateUnitedStatesStateOrTerritory(
args.StateOfResidency,
LabelStateOfResidency,
ParamStateOfResidency);
if (_validator.Errors.Any())
{
return null;
}
// Build a list of arguments for the full EFC calculation using assumed
// values gleaned from the "simplified" values provided
bool isFirstParentWorking = false;
bool isSecondParentWorking = false;
double firstParentWorkIncome = 0;
double secondParentWorkIncome = 0;
if (incomeEarnedBy == IncomeEarnedBy.One)
{
isFirstParentWorking = true;
firstParentWorkIncome = parentIncome;
}
if (incomeEarnedBy == IncomeEarnedBy.Both)
{
isFirstParentWorking = isSecondParentWorking = true;
firstParentWorkIncome = secondParentWorkIncome = (parentIncome / 2);
}
HouseholdMember firstParent = new HouseholdMember
{
IsWorking = isFirstParentWorking,
WorkIncome = firstParentWorkIncome
};
HouseholdMember secondParent = null;
if (maritalStatus == MaritalStatus.MarriedRemarried)
{
secondParent = new HouseholdMember
{
IsWorking = isSecondParentWorking,
WorkIncome = secondParentWorkIncome
};
}
// ASSUME: Student is working
HouseholdMember student = new HouseholdMember
{
IsWorking = true,
WorkIncome = studentIncome
};
// Build calculation arguments
DependentEfcCalculatorArguments parsedArgs = new DependentEfcCalculatorArguments
{
FirstParent = firstParent,
SecondParent = secondParent,
Student = student,
// ASSUME: "Age of Oldest Parent" is 45
OldestParentAge = 45,
// ASSUME: "Parent's AGI" == "Parent's Income"
ParentAdjustedGrossIncome = parentIncome,
// ASSUME: Parents are tax filers
AreParentsTaxFilers = true,
ParentIncomeTaxPaid = parentIncomeTaxPaid,
// ASSUME: "Parent's Untaxed Income and Benefits" == "Parent's Other Income"
ParentUntaxedIncomeAndBenefits = parentOtherIncome,
// ASSUME: "Parent's Additional Financial Information" is zero
ParentAdditionalFinancialInfo = 0,
// ASSUME: "Student's AGI" == "Student's Income"
StudentAdjustedGrossIncome = studentIncome,
// ASSUME: Student is a tax filer
IsStudentTaxFiler = true,
StudentIncomeTaxPaid = studentIncomeTaxPaid,
// ASSUME: "Student's Untaxed Income and Benefits" == "Student's Other Income"
StudentUntaxedIncomeAndBenefits = studentOtherIncome,
// ASSUME: "Student's Additional Financial Information" is zero
StudentAdditionalFinancialInfo = 0,
// ASSUME: "Parent's Cash, Savings, and Checking" == "Parent's Assets"
ParentCashSavingsChecking = parentAssets,
// ASSUME: "Parent's Net Worth of Investments" is zero
ParentInvestmentNetWorth = 0,
// ASSUME: "Parent's Net Worth of Business and/or Investment Farm" is zero
ParentBusinessFarmNetWorth = 0,
// ASSUME: "Student's Cash, Savings, and Checking" == "Student's Assets"
StudentCashSavingsChecking = studentAssets,
// ASSUME: "Student's Net Worth of Investments" is zero
StudentInvestmentNetWorth = 0,
// ASSUME: "Student's Net Worth of Business and/or Investment Farm" is zero
StudentBusinessFarmNetWorth = 0,
MaritalStatus = maritalStatus,
StateOfResidency = stateOfResidency,
NumberInHousehold = numberInHousehold,
NumberInCollege = numberInCollege,
// ASSUME: Student is NOT qualified for simplified formula
IsQualifiedForSimplified = false,
// ASSUME: Nine months of enrollment
MonthsOfEnrollment = 9
};
return parsedArgs;
}
public IndependentEfcCalculatorArguments ValidateSimpleIndependentEfcCalculatorArguments(RawSimpleIndependentEfcCalculatorArguments args)
{
if (args == null)
{
throw new ArgumentException("No raw arguments provided");
}
// Marital Status
MaritalStatus maritalStatus
= _validator.ValidateMaritalStatus(
args.MaritalStatus,
LabelIndStudentMaritalStatus,
ParamMaritalStatus);
// Student Age
int studentAge =
_validator.ValidateNonZeroInteger(
args.StudentAge,
LabelIndStudentAge,
ParamIndStudentAge);
// Student Income
double studentIncome =
_validator.ValidatePositiveMoneyValue(
args.StudentIncome,
LabelIndStudentIncome,
ParamIndStudentIncome);
// Student Other Income
double studentOtherIncome =
_validator.ValidatePositiveMoneyValue(
args.StudentOtherIncome,
LabelIndStudentOtherIncome,
ParamIndStudentOtherIncome);
// Student Income Earned By
IncomeEarnedBy incomeEarnedBy =
_validator.ValidateIncomeEarnedBy(
args.StudentIncomeEarnedBy,
LabelIndStudentIncomeEarnedBy,
ParamIndStudentIncomeEarnedBy);
// CHECK: If Single/Separated/Divorced, "Student's Income Earned By" can not be "Both"
if (maritalStatus == MaritalStatus.SingleSeparatedDivorced && incomeEarnedBy == IncomeEarnedBy.Both)
{
_validator.Errors.Add(new ValidationError(ParamIndStudentIncomeEarnedBy,
String.Format(@"{0} was ""Single/Separated/Divorced"", but {1} was marked as earned by both student and spouse",
LabelIndStudentMaritalStatus, LabelIndStudentIncomeEarnedBy)));
}
// CHECK: If "Student's Income Earned By" is "None", then "Parent Income" must be 0
if (incomeEarnedBy == IncomeEarnedBy.None && studentIncome > 0)
{
_validator.Errors.Add(new ValidationError(ParamParentIncome,
String.Format(@"{0} was marked as earned by neither student nor spouse, but {1} was greater than 0",
LabelIndStudentIncomeEarnedBy, LabelIndStudentIncome)));
}
// Student Income Tax Paid
double studentIncomeTaxPaid =
_validator.ValidatePositiveMoneyValue(
args.StudentIncomeTax,
LabelIndStudentIncomeTax,
ParamIndStudentIncomeTax);
// Student Assets
double studentAssets =
_validator.ValidatePositiveMoneyValue(
args.StudentAssets,
LabelIndStudentAssets,
ParamIndStudentAssets);
// Number in Household
int numberInHousehold =
_validator.ValidateNonZeroInteger(
args.NumberInHousehold,
LabelNumInHousehold,
ParamNumInHousehold);
// Number in College
int numberInCollege =
_validator.ValidateNonZeroInteger(
args.NumberInCollege,
LabelNumInCollege,
ParamNumInCollege);
// CHECK: Number in Household must be greater than or equal to Number in College
if (numberInCollege > numberInHousehold)
{
_validator.Errors.Add(new ValidationError(ParamNumInCollege,
String.Format(@"{0} must be less than or equal to {1}",
LabelNumInCollege, LabelNumInHousehold)));
}
// Has Dependents
bool hasDependents =
_validator.ValidateBoolean(
args.HasDependents,
LabelIndStudentHasDep,
ParamIndStudentHasDep);
// CHECK: If student has dependents, Number in Household can not be less than two
if (hasDependents && numberInHousehold < 2)
{
_validator.Errors.Add(new ValidationError(ParamIndStudentHasDep,
String.Format(@"Student has dependents, but {0} was less than two.",
LabelNumInHousehold)));
}
// State of Residency
UnitedStatesStateOrTerritory stateOfResidency =
_validator.ValidateUnitedStatesStateOrTerritory(
args.StateOfResidency,
LabelStateOfResidency,
ParamStateOfResidency);
if (_validator.Errors.Any())
{
return null;
}
// Build a list of arguments for the full EFC calculation using assumed
// values gleaned from the "simplified" values provided
bool isStudentWorking = false;
bool isSpouseWorking = false;
double studentWorkIncome = 0;
double spouseWorkIncome = 0;
if(incomeEarnedBy == IncomeEarnedBy.One)
{
isStudentWorking = true;
studentWorkIncome = studentIncome;
}
if(incomeEarnedBy == IncomeEarnedBy.Both)
{
isStudentWorking = isSpouseWorking = true;
studentWorkIncome = spouseWorkIncome = (studentIncome/2);
}
HouseholdMember student = new HouseholdMember
{
IsWorking = isStudentWorking,
WorkIncome = studentWorkIncome
};
HouseholdMember spouse = null;
if (maritalStatus == MaritalStatus.MarriedRemarried)
{
spouse = new HouseholdMember
{
IsWorking = isSpouseWorking,
WorkIncome = spouseWorkIncome
};
}
IndependentEfcCalculatorArguments parsedArgs = new IndependentEfcCalculatorArguments
{
Student = student,
Spouse = spouse,
// ASSUME: "Student and Spouse's Income" == "Student and Spouse's AGI"
AdjustedGrossIncome = studentIncome,
// ASSUME: Student and Spouse are tax filers
AreTaxFilers = true,
IncomeTaxPaid = studentIncomeTaxPaid,
// ASSUME: "Student and Spouse's Untaxed Income and Benefits" == "Student and Spouse's Other Income"
UntaxedIncomeAndBenefits = studentOtherIncome,
// ASSUME: "Student and Spouse's Additional Financial Information" is zero
AdditionalFinancialInfo = 0,
// ASSUME: "Student's and Spouse's Cash, Savings, and Checking" == "Student and Spouse's Assets"
CashSavingsCheckings = studentAssets,
// ASSUME: "Student and Spouse's Net Worth of Investments" is zero
InvestmentNetWorth = 0,
// ASSUME: "Student and Spouse's Net Worth of Business and/or Investment Farm" is zero
BusinessFarmNetWorth = 0,
HasDependents = hasDependents,
MaritalStatus = maritalStatus,
StateOfResidency = stateOfResidency,
NumberInHousehold = numberInHousehold,
NumberInCollege = numberInCollege,
Age = studentAge,
// ASSUME: Student is NOT qualified for simplified formula
IsQualifiedForSimplified = false,
// ASSUME: Nine months of enrollment
MonthsOfEnrollment = 9
};
return parsedArgs;
}
}
}