public RenewalGenerationResults GenerateRenewalLetters(string InputFile, string OutPutFolder) { try { if (!File.Exists(InputFile)) { throw new FileNotFoundException("File Not Found", InputFile); } if (!Directory.Exists(OutPutFolder)) { throw new DirectoryNotFoundException("Folder Not Found"); } int lettersNotGeneratedCount = 0; DAL.DataRepo dataRepo = new DAL.DataRepo(OutPutFolder); List <DAL.CustomerItem> customerList = dataRepo.GetCustomersFromInputFile(InputFile); for (int i = 0; i < customerList.Count; i++) { DAL.CustomerItem customerItem = customerList[i]; if (customerItem.IsValid) { customerItem.CalculateMonthlyPayments(); string letterBody = generateLetterBody(customerItem); DAL.CreateResults sResults = dataRepo.CreateReminderLetter(letterBody, customerItem.ID, customerItem.FirstName + customerItem.SurName); if (!sResults.Success) { //sResults.Message //This file has not been created so Log this. Perhaps a monitor would be set to alert Support in this eventuality. log.Error(sResults.Message); lettersNotGeneratedCount++; } } else { //Log that the input row is invalid. log.Error(string.Format("Row {0} of file [{1}] has invalid items.", i.ToString(), InputFile)); } } return(new RenewalGenerationResults(customerList.Count - lettersNotGeneratedCount, lettersNotGeneratedCount)); } catch (Exception ex) { throw ex; } }
private string generateLetterBody(DAL.CustomerItem customerItem) { StringBuilder sb = new StringBuilder(); sb.AppendLine(DateTime.Now.ToString("dd/MM/yyyy")); sb.AppendLine(""); string nameString = ((customerItem.Title.Trim().Trim() + " " + customerItem.FirstName.Trim()).Trim() + " " + customerItem.SurName.Trim()).Trim(); sb.AppendLine(string.Format("FAO: {0}", nameString)); sb.AppendLine(""); sb.AppendLine("Your Renewal"); sb.AppendLine(""); nameString = customerItem.Title.Trim().Trim() + " " + customerItem.SurName.Trim(); sb.AppendLine(string.Format("Dear {0}", nameString)); sb.AppendLine(""); sb.AppendLine("We hereby invite you to renew your Insurance Policy, subject to the following terms."); sb.AppendLine(""); sb.AppendLine(string.Format("Your chosen insurance product is {0}.", customerItem.ProductName)); sb.AppendLine(""); sb.AppendLine(string.Format("The amount payable to you in the event of a valid claim will be £{0}.", String.Format("{0:#,0.00}", customerItem.PaymentAmount))); sb.AppendLine(""); sb.AppendLine(string.Format("Your annual premium will be £{0}.", String.Format("{0:0.00}", customerItem.AnnualPremium))); sb.AppendLine(""); sb.AppendLine(string.Format("If you choose to pay by Direct Debit, we will add a credit charge of £{0}, bringing the total to " + "£{1}. This is payable by an initial payment of £{2}, " + "followed by 11 payments of £{3} each.", String.Format("{0:0.00}", customerItem.CreditCharge), String.Format("{0:0.00}", customerItem.TotalPremium), String.Format("{0:0.00}", customerItem.InitialMonthlyPaymentAmount), String.Format("{0:0.00}", customerItem.OtherMonthlyPaymentsAmount) )); sb.AppendLine(""); sb.AppendLine(string.Format("Please get in touch with us to arrange your renewal by visiting {0} or calling us on {1}.", renewalWebLink, renewalPhone)); sb.AppendLine(""); sb.AppendLine("Kind Regards"); sb.AppendLine(renewalSignature); return(sb.ToString()); }