Beispiel #1
0
        public static CurrentMonth GetCurrentMonth(string userId)
        {
            try
            {
                DbMonth       dbThisMonth   = LogService.Data.GetDbMonthByDate(userId, DateTime.Now);
                DbPreferences dbPreferences = LogService.Data.GetPreferencesByUserId(userId);

                string _monthName = MonthOrdinalToName(dbThisMonth.StartDate.Month);



                List <double> _ajustments = new List <double>();
                //int _yearId = 0;
                DateTime _yearStartDate       = new DateTime();
                int      _year                = _yearStartDate.Year;
                double   _yearStartAmount     = 0;
                int      _yearGoal            = 0;
                bool     _isCurrentYear       = true;
                double   _monthSaved          = dbThisMonth.GrossCredits - dbThisMonth.GrossDebits;
                double   _balance             = CalculateBalance(dbThisMonth.StartAmount, dbThisMonth.GrossCredits, dbThisMonth.GrossDebits);
                int      _monthCalculatedGoal = CalculateMonthGoal(
                    currentBalance: _balance,
                    yearGoal: dbPreferences.YearGoal,
                    startDate: dbThisMonth.StartDate,
                    monthFixedGoal: dbPreferences.MonthFixedGoal);
                int _goal = dbPreferences.MonthGoalType == MonthGoalType.Fixed
                    ? dbPreferences.MonthFixedGoal : _monthCalculatedGoal;
                double        _yearSaved        = _balance - _yearStartAmount;
                double        _amountLeftToSave = _goal - _balance;
                List <string> _categories       = new List <string>();

                return(new CurrentMonth(
                           monthId: dbThisMonth.MonthId,
                           previousMonthId: dbThisMonth.PreviousMonthId,
                           startDate: dbThisMonth.StartDate,
                           monthName: _monthName,
                           goal: _goal,
                           monthFixedGoal: dbPreferences.MonthFixedGoal,
                           monthGoalType: dbPreferences.MonthGoalType,
                           monthCalculatedGoal: _monthCalculatedGoal,
                           grossCredits: dbThisMonth.GrossCredits,
                           grossDebits: dbThisMonth.GrossDebits,
                           startAmount: dbThisMonth.StartAmount,
                           ajustments: _ajustments,
                           year: _year,
                           yearStartDate: _yearStartDate,
                           yearStartAmount: _yearStartAmount,
                           yearGoal: _yearGoal,
                           isCurrentYear: _isCurrentYear,
                           yearSaved: _yearSaved,
                           monthSaved: _monthSaved,
                           balance: _balance,
                           amountLeftToSave: _amountLeftToSave,
                           categories: _categories));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #2
0
            public static DbPreferences GetPreferencesByUserId(string userId)
            {
                var dbPreferences = new DbPreferences();

                try
                {
                    DataProvider.ExecuteCmd(GetConnection, "dbo.sp_Month_Select_ByMonthId",
                                            inputParamMapper : delegate(SqlParameterCollection paramCollection)
                    {
                        paramCollection.AddWithValue("@userId", userId);
                    },
                                            map : delegate(IDataReader reader, short set)
                    {
                        int startingIndex = 0;

                        dbPreferences = new DbPreferences(
                            preferenceId: reader.GetSafeInt32(startingIndex++),
                            userId: reader.GetSafeString(startingIndex++),
                            monthGoalType: (MonthGoalType)reader.GetSafeInt32(startingIndex++),
                            monthFixedGoal: reader.GetSafeInt32(startingIndex++),
                            yearGoal: reader.GetSafeInt32(startingIndex++),
                            yearStartAmount: reader.GetSafeDouble(startingIndex++));
                    });
                }
                catch (Exception e)
                {
                    throw e;
                }

                return(dbPreferences);
            }
Beispiel #3
0
        public static Month RenderMonth(DbMonth dbMonth)
        {
            DbPreferences dbPrederences = LogService.Data.GetPreferencesByUserId(dbMonth.UserId);
            List <double> adjustments   = LogService.Data.GetMonthAdjustments(dbMonth.MonthId);


            bool isCurrentMonth = (GetMonthStartOfDate(DateTime.Today) == GetMonthStartOfDate(dbMonth.StartDate));

            return(new MonthSnapshot(
                       monthId: dbMonth.MonthId,
                       previousMonthId: dbMonth.PreviousMonthId,
                       startDate: dbMonth.StartDate,
                       monthName: MonthOrdinalToName(dbMonth.StartDate.Month),
                       goal: 0,
                       grossCredits: dbMonth.GrossCredits,
                       grossDebits: dbMonth.GrossDebits,
                       startAmount: dbMonth.StartAmount,
                       adustments: adjustments,
                       year: dbMonth.StartDate.Year,
                       yearStartDate: LogService.GetYearStartOfDate(dbMonth.StartDate),
                       isCurrentMonth: isCurrentMonth));
        }