protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { // Collect user input RawIndependentEfcCalculatorArguments rawArgs = new RawIndependentEfcCalculatorArguments(); rawArgs.StudentAge = inputStudentAge.Text; rawArgs.MaritalStatus = inputMaritalStatus.SelectedValue; rawArgs.StateOfResidency = inputStateOfResidency.SelectedValue; rawArgs.IsStudentWorking = inputStudentWorking.SelectedValue; rawArgs.StudentWorkIncome = inputStudentWorkIncome.Text; rawArgs.IsSpouseWorking = inputSpouseWorking.SelectedValue; rawArgs.SpouseWorkIncome = inputSpouseWorkIncome.Text; rawArgs.StudentAgi = inputStudentAgi.Text; rawArgs.IsStudentTaxFiler = inputStudentTaxFiler.SelectedValue; rawArgs.StudentIncomeTax = inputStudentIncomeTax.Text; rawArgs.StudentUntaxedIncomeAndBenefits = inputStudentUntaxedIncomeAndBenefits.Text; rawArgs.StudentAdditionalFinancialInfo = inputStudentAdditionalFinancialInfo.Text; rawArgs.StudentCashSavingsChecking = inputStudentCashSavingsChecking.Text; rawArgs.StudentInvestmentNetWorth = inputStudentInvestmentNetWorth.Text; rawArgs.StudentBusinessFarmNetWorth = inputStudentBusinessFarmNetWorth.Text; rawArgs.HasDependents = inputHasDependents.SelectedValue; rawArgs.NumberInHousehold = inputNumberInHousehold.Text; rawArgs.NumberInCollege = inputNumberInCollege.Text; rawArgs.MonthsOfEnrollment = "9"; rawArgs.IsQualifiedForSimplified = "false"; // Validate user input AidEstimationValidator validator = new AidEstimationValidator(); IndependentEfcCalculatorArguments args = validator.ValidateIndependentEfcCalculatorArguments(rawArgs); // If validation fails, display errors if (validator.Errors.Count > 0) { errorList.DataSource = validator.Errors; errorList.DataBind(); return; } // Calculate EfcCalculator calculator = EfcCalculatorConfigurationManager.GetEfcCalculator("1617"); EfcProfile profile = calculator.GetIndependentEfcProfile(args); // Display Results formPlaceholder.Visible = false; resultsPlaceholder.Visible = true; studentContributionOutput.Text = profile.StudentContribution.ToString(); expectedFamilyContributionOutput.Text = profile.ExpectedFamilyContribution.ToString(); } }
public IndependentEfcCalculatorArguments ValidateIndependentEfcCalculatorArguments(RawIndependentEfcCalculatorArguments args) { if (args == null) { throw new ArgumentException("No raw arguments provided"); } // Age int age = _validator.ValidateNonZeroInteger( args.StudentAge, LabelIndStudentAge, ParamIndStudentAge); // Marital Status MaritalStatus maritalStatus = _validator.ValidateMaritalStatus( args.MaritalStatus, LabelIndStudentMaritalStatus, ParamMaritalStatus); // Is Student Working? bool isStudentWorking = _validator.ValidateBoolean( args.IsStudentWorking, LabelIsStudentWorking, ParamIsStudentWorking); // Student Work Income double studentWorkIncome = isStudentWorking ? _validator.ValidatePositiveMoneyValue( args.StudentWorkIncome, LabelStudentWorkIncome, ParamStudentWorkIncome) : 0; HouseholdMember student = new HouseholdMember { IsWorking = isStudentWorking, WorkIncome = studentWorkIncome }; HouseholdMember spouse = null; if (maritalStatus == MaritalStatus.MarriedRemarried) { // Is Spouse Working? bool isSpouseWorking = _validator.ValidateBoolean( args.IsSpouseWorking, LabelIsSpouseWorking, ParamIsSpouseWorking); // Spouse Work Income double spouseWorkIncome = isSpouseWorking ? _validator.ValidatePositiveMoneyValue( args.SpouseWorkIncome, LabelSpouseWorkIncome, ParamSpouseWorkIncome) : 0; spouse = new HouseholdMember { IsWorking = isSpouseWorking, WorkIncome = spouseWorkIncome }; } // Student and Spouse's AGI double agi = _validator.ValidateMoneyValue( args.StudentAgi, LabelIndStudentAgi, ParamIndStudentAgi); // Are Tax Filers? bool areTaxFilers = _validator.ValidateBoolean( args.IsStudentTaxFiler, LabelIsIndStudentTaxFiler, ParamIsIndStudentTaxFiler); // Income Tax Paid double incomeTaxPaid = _validator.ValidateMoneyValue( args.StudentIncomeTax, LabelIndStudentIncomeTax, ParamIndStudentIncomeTax); // Untaxed Income And Benefits double untaxedIncomeAndBenefits = _validator.ValidatePositiveMoneyValue( args.StudentUntaxedIncomeAndBenefits, LabelIndStudentUntaxedIncomeAndBenefits, ParamIndStudentUntaxedIncomeAndBenefits); // Additional Financial Information double additionalFinancialInfo = _validator.ValidatePositiveMoneyValue( args.StudentAdditionalFinancialInfo, LabelIndStudentAdditionalFinancialInfo, ParamIndStudentAdditionalFinancialInfo); // Cash, Savings, Checking double cashSavingsChecking = _validator.ValidatePositiveMoneyValue( args.StudentCashSavingsChecking, LabelIndStudentCashSavingsChecking, ParamIndStudentCashSavingsChecking); // Investment Net Worth double investmentNetWorth = _validator.ValidateMoneyValue( args.StudentInvestmentNetWorth, LabelIndStudentInvestmentNetWorth, ParamIndStudentInvestmentNetWorth); // Business Farm Net Worth double businessFarmNetWorth = _validator.ValidateMoneyValue( args.StudentBusinessFarmNetWorth, LabelIndStudentBusinessFarmNetWorth, ParamIndStudentBusinessFarmNetWorth); // Has Dependents? bool hasDependents = _validator.ValidateBoolean( args.HasDependents, LabelIndStudentHasDep, ParamIndStudentHasDep); // State of Residency UnitedStatesStateOrTerritory stateOfResidency = _validator.ValidateUnitedStatesStateOrTerritory( args.StateOfResidency, LabelStateOfResidency, ParamStateOfResidency); // 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))); } // 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))); } // Is Qualified for Simplified bool isQualifiedForSimplified = _validator.ValidateBoolean( args.IsQualifiedForSimplified, LabelIsQualifiedForSimplified, ParamIsQualifiedForSimplified); // Months of Enrollment int monthsOfEnrollment = _validator.ValidateNonZeroInteger( args.MonthsOfEnrollment, LabelMonthsOfEnrollment, ParamMonthsOfEnrollment); if (_validator.Errors.Any()) { return null; } // Build calculation arguments IndependentEfcCalculatorArguments parsedArgs = new IndependentEfcCalculatorArguments { Student = student, Spouse = spouse, AdjustedGrossIncome = agi, AreTaxFilers = areTaxFilers, IncomeTaxPaid = incomeTaxPaid, UntaxedIncomeAndBenefits = untaxedIncomeAndBenefits, AdditionalFinancialInfo = additionalFinancialInfo, CashSavingsCheckings = cashSavingsChecking, InvestmentNetWorth = investmentNetWorth, BusinessFarmNetWorth = businessFarmNetWorth, HasDependents = hasDependents, MaritalStatus = maritalStatus, StateOfResidency = stateOfResidency, NumberInHousehold = numberInHousehold, NumberInCollege = numberInCollege, Age = age, IsQualifiedForSimplified = isQualifiedForSimplified, MonthsOfEnrollment = monthsOfEnrollment }; return parsedArgs; }
public IndependentEfcCalculatorArguments ValidateIndependentEfcCalculatorArguments(RawIndependentEfcCalculatorArguments args) { if (args == null) { throw new ArgumentException("No raw arguments provided"); } // Age int age = _validator.ValidateNonZeroInteger( args.StudentAge, LabelIndStudentAge, ParamIndStudentAge); // Marital Status MaritalStatus maritalStatus = _validator.ValidateMaritalStatus( args.MaritalStatus, LabelIndStudentMaritalStatus, ParamMaritalStatus); // Is Student Working? bool isStudentWorking = _validator.ValidateBoolean( args.IsStudentWorking, LabelIsStudentWorking, ParamIsStudentWorking); // Student Work Income double studentWorkIncome = isStudentWorking ? _validator.ValidatePositiveMoneyValue( args.StudentWorkIncome, LabelStudentWorkIncome, ParamStudentWorkIncome) : 0; HouseholdMember student = new HouseholdMember { IsWorking = isStudentWorking, WorkIncome = studentWorkIncome }; HouseholdMember spouse = null; if (maritalStatus == MaritalStatus.MarriedRemarried) { // Is Spouse Working? bool isSpouseWorking = _validator.ValidateBoolean( args.IsSpouseWorking, LabelIsSpouseWorking, ParamIsSpouseWorking); // Spouse Work Income double spouseWorkIncome = isSpouseWorking ? _validator.ValidatePositiveMoneyValue( args.SpouseWorkIncome, LabelSpouseWorkIncome, ParamSpouseWorkIncome) : 0; spouse = new HouseholdMember { IsWorking = isSpouseWorking, WorkIncome = spouseWorkIncome }; } // Student and Spouse's AGI double agi = _validator.ValidateMoneyValue( args.StudentAgi, LabelIndStudentAgi, ParamIndStudentAgi); // Are Tax Filers? bool areTaxFilers = _validator.ValidateBoolean( args.IsStudentTaxFiler, LabelIsIndStudentTaxFiler, ParamIsIndStudentTaxFiler); // Income Tax Paid double incomeTaxPaid = _validator.ValidateMoneyValue( args.StudentIncomeTax, LabelIndStudentIncomeTax, ParamIndStudentIncomeTax); // Untaxed Income And Benefits double untaxedIncomeAndBenefits = _validator.ValidatePositiveMoneyValue( args.StudentUntaxedIncomeAndBenefits, LabelIndStudentUntaxedIncomeAndBenefits, ParamIndStudentUntaxedIncomeAndBenefits); // Additional Financial Information double additionalFinancialInfo = _validator.ValidatePositiveMoneyValue( args.StudentAdditionalFinancialInfo, LabelIndStudentAdditionalFinancialInfo, ParamIndStudentAdditionalFinancialInfo); // Cash, Savings, Checking double cashSavingsChecking = _validator.ValidatePositiveMoneyValue( args.StudentCashSavingsChecking, LabelIndStudentCashSavingsChecking, ParamIndStudentCashSavingsChecking); // Investment Net Worth double investmentNetWorth = _validator.ValidateMoneyValue( args.StudentInvestmentNetWorth, LabelIndStudentInvestmentNetWorth, ParamIndStudentInvestmentNetWorth); // Business Farm Net Worth double businessFarmNetWorth = _validator.ValidateMoneyValue( args.StudentBusinessFarmNetWorth, LabelIndStudentBusinessFarmNetWorth, ParamIndStudentBusinessFarmNetWorth); // Has Dependents? bool hasDependents = _validator.ValidateBoolean( args.HasDependents, LabelIndStudentHasDep, ParamIndStudentHasDep); // State of Residency UnitedStatesStateOrTerritory stateOfResidency = _validator.ValidateUnitedStatesStateOrTerritory( args.StateOfResidency, LabelStateOfResidency, ParamStateOfResidency); // 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))); } // 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))); } // Is Qualified for Simplified bool isQualifiedForSimplified = _validator.ValidateBoolean( args.IsQualifiedForSimplified, LabelIsQualifiedForSimplified, ParamIsQualifiedForSimplified); // Months of Enrollment int monthsOfEnrollment = _validator.ValidateNonZeroInteger( args.MonthsOfEnrollment, LabelMonthsOfEnrollment, ParamMonthsOfEnrollment); if (_validator.Errors.Count > 0) { return(null); } // Build calculation arguments IndependentEfcCalculatorArguments parsedArgs = new IndependentEfcCalculatorArguments { Student = student, Spouse = spouse, AdjustedGrossIncome = agi, AreTaxFilers = areTaxFilers, IncomeTaxPaid = incomeTaxPaid, UntaxedIncomeAndBenefits = untaxedIncomeAndBenefits, AdditionalFinancialInfo = additionalFinancialInfo, CashSavingsCheckings = cashSavingsChecking, InvestmentNetWorth = investmentNetWorth, BusinessFarmNetWorth = businessFarmNetWorth, HasDependents = hasDependents, MaritalStatus = maritalStatus, StateOfResidency = stateOfResidency, NumberInHousehold = numberInHousehold, NumberInCollege = numberInCollege, Age = age, IsQualifiedForSimplified = isQualifiedForSimplified, MonthsOfEnrollment = monthsOfEnrollment }; return(parsedArgs); }