public List <MaturityDataViewModel> ProcessRawData(string[] rawData) { _maturityData.Clear(); for (var i = 1; i < rawData.Length; i++) { var splitData = rawData[i].Split(',').ToList(); var membership = splitData[3].ToUpper() == "Y" ? Enums.YesNo.Yes : Enums.YesNo.No; var policyStartdate = DateTime.Parse(splitData[1]); double managementFeeMultiplier = 0.0; string policyType = ""; //policyType has been set here just to make it easy to debug problems //The calculation is also done here, but maintainability could be a problem //if the number of rules grows. possible solutions might be to call a rules engine, //or pass in a set of rules which would be matched to policy type if (policyStartdate < new DateTime(1990, 1, 1, 0, 0, 0)) { policyType = "A"; managementFeeMultiplier = 0.03; } else if (policyStartdate >= new DateTime(1990, 1, 1, 0, 0, 0) && membership == Enums.YesNo.Yes) { policyType = "C"; managementFeeMultiplier = 0.07; } else if (membership == Enums.YesNo.Yes) { policyType = "B"; managementFeeMultiplier = 0.05; } var item = new MaturityDataViewModel() { PolicyNumber = splitData[0], PolicyStartDate = DateTime.Parse(splitData[1]), Premiums = double.Parse(splitData[2]), Membership = membership, DiscretionaryBonus = double.Parse(splitData[4]), UpliftPercentage = double.Parse(splitData[5]), PolicyType = policyType, ManagementFeeMultiplier = managementFeeMultiplier }; item.MaturityValue = ((item.Premiums - item.ManagementFeeMultiplier * item.Premiums) + item.DiscretionaryBonus) * (1 + (item.UpliftPercentage / 100)); _maturityData.Add(item); } return(_maturityData); }
public ActionResult Index() { // Call Service to get Maturity Data and Calculate Values IEnumerable <MaturityDataModel> maturityData = _serv.GetMaturityDataAndCalculateValues(); // Call Service to Generate XML file bool xmlFileGenerated = _serv.GenerateXMLFile(maturityData); // Populate ViewModel so we can put the results on the page MaturityDataViewModel model = new MaturityDataViewModel { MaturityDataResults = maturityData, XMLFileGenerated = xmlFileGenerated }; return(View(model)); }