private static List <EasSubmission> BuildSubmissionList(int ukprn, IEnumerable <EasCsvRecord> easCsvRecords, Guid submissionId) { var ukprnString = ukprn.ToString(); List <int> distinctCollectionPeriods = new List <int>(); var submissionList = new List <EasSubmission>(); foreach (var record in easCsvRecords) { distinctCollectionPeriods.Add( CollectionPeriodHelper.GetCollectionPeriod(Convert.ToInt32(record.CalendarYear), Convert.ToInt32(record.CalendarMonth))); } distinctCollectionPeriods = distinctCollectionPeriods.Distinct().ToList(); foreach (var collectionPeriod in distinctCollectionPeriods) { var easSubmission = new EasSubmission() { SubmissionId = submissionId, CollectionPeriod = collectionPeriod, DeclarationChecked = true, NilReturn = false, ProviderName = string.Empty, Ukprn = ukprnString, UpdatedOn = DateTime.Now, }; submissionList.Add(easSubmission); } return(submissionList); }
private static List <EasSubmissionValue> BuildEasSubmissionValues(IEnumerable <EasCsvRecord> easCsvRecords, List <PaymentType> paymentTypes, Guid submissionId) { var submissionValuesList = new List <EasSubmissionValue>(); foreach (var easRecord in easCsvRecords) { var paymentType = paymentTypes.FirstOrDefault(x => x.FundingLine?.Name.RemoveWhiteSpacesNonAlphaNumericCharacters().ToLower() == easRecord.FundingLine.RemoveWhiteSpacesNonAlphaNumericCharacters().ToLower() && x.AdjustmentType?.Name.RemoveWhiteSpacesNonAlphaNumericCharacters().ToLower() == easRecord.AdjustmentType.RemoveWhiteSpacesNonAlphaNumericCharacters().ToLower()); if (paymentType is null) { throw new Exception( $"Funding Line : {easRecord.FundingLine} , AdjustmentType combination : {easRecord.AdjustmentType} does not exist."); } var easSubmissionValues = new EasSubmissionValue { PaymentId = paymentType.PaymentId, CollectionPeriod = CollectionPeriodHelper.GetCollectionPeriod(Convert.ToInt32(easRecord.CalendarYear), Convert.ToInt32(easRecord.CalendarMonth)), PaymentValue = decimal.Parse(easRecord.Value), DevolvedAreaSoF = string.IsNullOrEmpty(easRecord.DevolvedAreaSourceOfFunding)? -1: int.Parse(easRecord.DevolvedAreaSourceOfFunding), SubmissionId = submissionId, }; submissionValuesList.Add(easSubmissionValues); } return(submissionValuesList); }
private bool CalendarMonthAndYearMustNotBeInfuture(EasCsvRecord record) { var collectionPeriod = CollectionPeriodHelper.GetCollectionPeriod(Convert.ToInt32(record.CalendarYear), Convert.ToInt32(record.CalendarMonth)); if (collectionPeriod > _returnPeriod) { return(false); } return(true); }
private List <EasCsvRecord> BuildEasCsvRecords(List <PaymentType> allPaymentTypes, List <EasSubmissionValue> easSubmissionValues) { List <EasCsvRecord> records = new List <EasCsvRecord>(); foreach (var submissionValue in easSubmissionValues) { var paymentType = allPaymentTypes.FirstOrDefault(x => x.PaymentId == submissionValue.PaymentId); var record = new EasCsvRecord { AdjustmentType = paymentType.AdjustmentType.Name, FundingLine = paymentType.FundingLine.Name, Value = submissionValue.PaymentValue.ToString(CultureInfo.InvariantCulture), CalendarYear = CollectionPeriodHelper.GetCalendarYearAndMonth(submissionValue.CollectionPeriod).Item1.ToString(), CalendarMonth = CollectionPeriodHelper.GetCalendarYearAndMonth(submissionValue.CollectionPeriod).Item2.ToString(), DevolvedAreaSourceOfFunding = submissionValue.DevolvedAreaSoF == -1? null : submissionValue.DevolvedAreaSoF.ToString() }; records.Add(record); } return(records); }