private static RecurringIncome _instance = null; //Singleton pattern public static RecurringIncome Instance() //Lazy Load initiation { if (_instance == null) { _instance = new RecurringIncome(); } return(_instance); }
public decimal MonthlyIncome() { List <Income> income = RecurringIncome.Instance().ParseIncomes(); decimal incomeTotal = 0; foreach (Income i in income) { incomeTotal += i.amount; } return(incomeTotal); }
public List <Income> ParseIncomes() { List <Income> income = new List <Income>(); try { List <string> item = new List <string>(); item = File.ReadAllLines(incomeDBFilePath).ToList(); foreach (string it in item) { string[] elements = it.Split(','); decimal incomeAmount = decimal.Parse(elements[0]); DateTime incomeDate = DateTime.Parse(elements[1]); Income newIncome = new Income(); newIncome.amount = incomeAmount; newIncome.date = incomeDate; income.Add(newIncome); } RecurringIncome recuringIncomeObj = new RecurringIncome(); List <RecurringIncome.Income> recuringIncome = recuringIncomeObj.ParseIncomes(); foreach (RecurringIncome.Income rIncome in recuringIncome) { DateTime dateForLoop = rIncome.dateFrom; while (dateForLoop < rIncome.dateUntil) { Income newrIncome = new Income(); newrIncome.amount = rIncome.amount; newrIncome.date = dateForLoop; income.Add(newrIncome); dateForLoop = dateForLoop.AddMonths(1); } } } catch (Exception e) { Logger.Instance().Log(e.ToString()); } return(income); }