Example #1
0
        private static RecurringIncomeController _instance = null; //Singleton pattern

        public static RecurringIncomeController Instance()         //Lazy Load initiation
        {
            if (_instance == null)
            {
                _instance = new RecurringIncomeController();
            }
            return(_instance);
        }
Example #2
0
        public decimal MonthlyIncome()
        {
            var income = ParseIncomes();

            decimal incomeTotal = 0;

            foreach (Smart_Saver_API.Models.IncomeDB oneIncome in income)
            {
                if (oneIncome.incomeDate.CheckIfCurrentMonth())
                {
                    incomeTotal += oneIncome.incomeAmount;
                }
            }

            return(incomeTotal + RecurringIncomeController.Instance().MonthlyIncome());
        }
Example #3
0
        public decimal OneUserMonthlyIncome(String username, String password)
        {
            var income = parseOneUserIncomes(username, password);

            decimal incomeTotal = 0;

            foreach (Smart_Saver_API.Models.IncomeDB oneIncome in income)
            {
                if (oneIncome.incomeDate.CheckIfCurrentMonth())
                {
                    incomeTotal += oneIncome.incomeAmount;
                }
            }

            return(incomeTotal + RecurringIncomeController.Instance().OneUserMonthlyIncome(username, password));
        }
Example #4
0
        private IEnumerable <Balance> CalculateEqualForOneUser(IEnumerable <Result> both, String username, String password)
        {
            bool           sign      = false;
            var            array     = both.ToArray();
            List <Balance> tBalances = new List <Balance>();

            for (int i = 0; i < array.Count(); i++)
            {
                if (i != array.Count() - 1)
                {
                    if (array[i].monthAndYear == array[i + 1].monthAndYear)
                    {
                        sign = true;
                        if (array[i].Year == DateTime.Now.Year && array[i].Month == DateTime.Now.Month)
                        {
                            Balance tBalance = new Balance()
                            {
                                Amount       = (array[i].amount - array[i + 1].amount) + RecurringIncomeController.Instance().OneUserMonthlyIncome(username, password),
                                monthAndYear = array[i].monthAndYear,
                                Year         = array[i].Year,
                                Month        = array[i].Month
                            };
                            tBalances.Add(tBalance);
                        }
                        else
                        {
                            Balance tBalance = new Balance()
                            {
                                Amount       = (array[i].amount - array[i + 1].amount),
                                monthAndYear = array[i].monthAndYear,
                                Year         = array[i].Year,
                                Month        = array[i].Month
                            };
                            tBalances.Add(tBalance);
                        }
                    }
                    else if (array[i].Type == "Expense" && sign == false)
                    {
                        if (array[i].Year == DateTime.Now.Year && array[i].Month == DateTime.Now.Month)
                        {
                            Balance tBalance = new Balance()
                            {
                                Amount       = (-array[i].amount) + RecurringIncomeController.Instance().OneUserMonthlyIncome(username, password),
                                monthAndYear = array[i].monthAndYear,
                                Year         = array[i].Year,
                                Month        = array[i].Month
                            };
                            tBalances.Add(tBalance);
                        }
                        else
                        {
                            Balance tBalance = new Balance()
                            {
                                Amount       = (-array[i].amount),
                                monthAndYear = array[i].monthAndYear,
                                Year         = array[i].Year,
                                Month        = array[i].Month
                            };
                            tBalances.Add(tBalance);
                        }
                    }
                    else if (array[i].Type == "Income" && sign == false)
                    {
                        if (array[i].Year == DateTime.Now.Year && array[i].Month == DateTime.Now.Month)
                        {
                            Balance tBalance = new Balance()
                            {
                                Amount       = (array[i].amount) + RecurringIncomeController.Instance().OneUserMonthlyIncome(username, password),
                                monthAndYear = array[i].monthAndYear,
                                Year         = array[i].Year,
                                Month        = array[i].Month
                            };
                            tBalances.Add(tBalance);
                        }
                        else
                        {
                            Balance tBalance = new Balance()
                            {
                                Amount       = (array[i].amount),
                                monthAndYear = array[i].monthAndYear,
                                Year         = array[i].Year,
                                Month        = array[i].Month
                            };
                            tBalances.Add(tBalance);
                        }
                    }
                    else
                    {
                        sign = false;
                    }
                }
                else
                {
                    if (array[i].Type == "Expense" && sign == false)
                    {
                        if (array[i].Year == DateTime.Now.Year && array[i].Month == DateTime.Now.Month)
                        {
                            Balance tBalance = new Balance()
                            {
                                Amount       = (-array[i].amount) + RecurringIncomeController.Instance().OneUserMonthlyIncome(username, password),
                                monthAndYear = array[i].monthAndYear,
                                Year         = array[i].Year,
                                Month        = array[i].Month
                            };
                            tBalances.Add(tBalance);
                        }
                        else
                        {
                            Balance tBalance = new Balance()
                            {
                                Amount       = (-array[i].amount),
                                monthAndYear = array[i].monthAndYear,
                                Year         = array[i].Year,
                                Month        = array[i].Month
                            };
                            tBalances.Add(tBalance);
                        }
                    }
                    else if (array[i].Type == "Income" && sign == false)
                    {
                        if (array[i].Year == DateTime.Now.Year && array[i].Month == DateTime.Now.Month)
                        {
                            Balance tBalance = new Balance()
                            {
                                Amount       = (array[i].amount) + RecurringIncomeController.Instance().OneUserMonthlyIncome(username, password),
                                monthAndYear = array[i].monthAndYear,
                                Year         = array[i].Year,
                                Month        = array[i].Month
                            };
                            tBalances.Add(tBalance);
                        }
                        else
                        {
                            Balance tBalance = new Balance()
                            {
                                Amount       = (array[i].amount),
                                monthAndYear = array[i].monthAndYear,
                                Year         = array[i].Year,
                                Month        = array[i].Month
                            };
                            tBalances.Add(tBalance);
                        }
                    }
                    else
                    {
                        sign = false;
                    }
                }
            }
            return(tBalances);
        }