private BudgetExpenditureEntity ConvertToBudgetRecord(ExpenditureFileRecord fileRecord, FiscalYearEntity fiscalYear)
        {
            var budget = GetBudget(fiscalYear);

            var expenditure = new BudgetExpenditureEntity();

            expenditure.BudgetId   = budget.BudgetId;
            expenditure.TopLevelId = fileRecord.Level1;
            expenditure.MidLevelId = fileRecord.Level2.Value;
            expenditure.CodeId     = fileRecord.Code.Value;

            //get property value using reflection
            var propertyName = fiscalYear.Name.Replace("-", "");
            var amountText   = (string)fileRecord.GetType().GetProperty(propertyName).GetMethod.Invoke(fileRecord, null);

            if (string.IsNullOrWhiteSpace(amountText))
            {
                return(null);
            }

            var amount = int.Parse(amountText, System.Globalization.NumberStyles.AllowThousands);

            expenditure.Amount = amount;

            return(expenditure);
        }
        private TotalEnrollmentEntity ConvertToTotalEnrollmentEntity(TotalDistrictEnrollmentFileRecord fileRecord, FiscalYearEntity fiscalYear)
        {
            var totalEnrollmentEntity = new TotalEnrollmentEntity();

            var district = Districts.SingleOrDefault(x => x.Name.Equals(fileRecord.District, StringComparison.InvariantCultureIgnoreCase));

            //skip record if we can't find district
            if (district == null)
            {
                Console.WriteLine($"Skipping Record... Unable to find district '{fileRecord.District}'");
                return(null);
            }

            //get property value using reflection
            var propertyName = fiscalYear.Name.Replace("-", "");
            var amountText   = (string)fileRecord.GetType().GetProperty(propertyName).GetMethod.Invoke(fileRecord, null);

            if (string.IsNullOrWhiteSpace(amountText))
            {
                return(null);
            }

            var amount = int.Parse(amountText, System.Globalization.NumberStyles.AllowThousands);

            totalEnrollmentEntity.DistrictId   = district.DistrictId;
            totalEnrollmentEntity.Enrollment   = amount;
            totalEnrollmentEntity.FiscalYearId = fiscalYear.FiscalYearId;

            return(totalEnrollmentEntity);
        }
 private BudgetEntity GetBudget(FiscalYearEntity fiscalYear)
 {
     return(BudgetByFiscalYear[fiscalYear.FiscalYearId]);
 }
        private void ConvertToTotalEnrollmentEntity(BudgetPropertiesFileRecord fileRecord, FiscalYearEntity fiscalYear)
        {
            var district = Districts.SingleOrDefault(x => x.Name.Equals(fileRecord.District, StringComparison.InvariantCultureIgnoreCase));

            //skip record if we can't find district
            if (district == null)
            {
                Console.WriteLine($"Skipping Record... Unable to find district '{fileRecord.District}'");
                return;
            }

            var budget    = Budgets.SingleOrDefault(x => x.DistrictId == district.DistrictId && x.FiscalYearId == fiscalYear.FiscalYearId);
            var newBudget = false;

            if (budget == null)
            {
                newBudget = true;
                budget    = new BudgetEntity {
                    DistrictId = district.DistrictId, FiscalYearId = fiscalYear.FiscalYearId
                };
            }
            //get property value using reflection
            var columnName   = fiscalYear.Name.Replace("-", "");
            var rawValueText = (string)fileRecord.GetType().GetProperty(columnName).GetMethod.Invoke(fileRecord, null);

            if (string.IsNullOrWhiteSpace(rawValueText))
            {
                return;
            }

            if (fileRecord.Attribute.Contains("Assessed", StringComparison.InvariantCultureIgnoreCase))
            {
                if (long.TryParse(rawValueText, NumberStyles.Any, CultureInfo.CurrentCulture, out var assessed))
                {
                    budget.Assessed = assessed;
                }
                else
                {
                    Console.WriteLine($"Skipping Record... Unable to parse '{fileRecord.Attribute}' value '{rawValueText}'");
                }
            }
            else if (fileRecord.Attribute.Contains("Homestead", StringComparison.InvariantCultureIgnoreCase))
            {
                if (int.TryParse(rawValueText, NumberStyles.Any, CultureInfo.CurrentCulture, out var homestead))
                {
                    budget.Homestead = homestead;
                }
                else
                {
                    Console.WriteLine($"Skipping Record... Unable to parse '{fileRecord.Attribute}' value '{rawValueText}'");
                }
            }
            else if (fileRecord.Attribute.Contains("Tax Levy", StringComparison.InvariantCultureIgnoreCase))
            {
                if (int.TryParse(rawValueText, NumberStyles.Any, CultureInfo.CurrentCulture, out var taxLeavy))
                {
                    budget.TaxLevy = taxLeavy;
                }
                else
                {
                    Console.WriteLine($"Skipping Record... Unable to parse '{fileRecord.Attribute}' value '{rawValueText}'");
                }
            }
            else if (fileRecord.Attribute.Contains("Collection", StringComparison.InvariantCultureIgnoreCase))
            {
                if (decimal.TryParse(rawValueText, NumberStyles.Any, CultureInfo.CurrentCulture, out var collectionRate))
                {
                    budget.CollectionRate = collectionRate;
                }
                else
                {
                    Console.WriteLine($"Skipping Record... Unable to parse '{fileRecord.Attribute}' value '{rawValueText}'");
                }
            }
            else if (fileRecord.Attribute.Contains("Millage", StringComparison.InvariantCultureIgnoreCase))
            {
                if (decimal.TryParse(rawValueText, NumberStyles.Any, CultureInfo.CurrentCulture, out var millage))
                {
                    budget.Millage = millage;
                }
                else
                {
                    Console.WriteLine($"Skipping Record... Unable to parse '{fileRecord.Attribute}' value '{rawValueText}'");
                }
            }

            if (newBudget)
            {
                Console.WriteLine("Adding New Budget");
                DbContext.Set <BudgetEntity>().Add(budget);
            }
        }