public UnitOfWork(ApplicationDbContext context) { _context = context; BudgetRepository = new BudgetRepository(context); BudgetItemsRepository = new BudgetItemsRepository(context); WeatherRepository = new WeatherRepository(context); }
public int NumMonthsUnderBudget(string user) { List <string> monthList = GetBudgetMonthsList(user); if (!monthList.Any()) { return(0); } var monthListNumbers = new List <int>(); foreach (var month in monthList) { monthListNumbers.Add(DateTime.ParseExact(month, "MMMM", CultureInfo.CurrentCulture).Month); } var underBudget = 0; var budgetRepo = new BudgetRepository(_context); foreach (var month in monthListNumbers) { var difference = budgetRepo.GetTotalBudgetLimitByMonth(month, user) - TotalSpentByMonth(month, user); if (difference > 0) { underBudget++; } } return(underBudget); }
public int NumMonthsUnderBudgetByCat(List <int> months, string user, int budgetType) { var budgetRepo = new BudgetRepository(_context); int numMonthsUnderBudget = 0; foreach (var month in months) { if (budgetRepo.GetBudgetLimitByLimitType(budgetType, month, user) - TotalSpentByBudgetCategory(month, user, budgetType) > 0) { numMonthsUnderBudget += 1; } } return(numMonthsUnderBudget); }
public float AmtOverOrUnderBudget(string user) { var monthListForUser = GetBudgetMonthNumbersList(user); if (!monthListForUser.Any()) { return(0.00f); } float totalBudget = 0; float totalSpent = 0; var budgetRepo = new BudgetRepository(_context); foreach (var month in monthListForUser) { totalBudget += budgetRepo.GetTotalBudgetLimitByMonth(month, user); totalSpent += TotalSpentByMonth(month, user); } return(totalBudget - totalSpent); }
public float AvgOverUnderByCat(List <int> months, string user, int budgetType) { var monthListForUser = GetBudgetMonthNumbersList(user); if (!monthListForUser.Any()) { return(0.00f); } float totalBudgetByCat = 0; float totalSpent = 0; var budgetRepo = new BudgetRepository(_context); foreach (var month in monthListForUser) { totalBudgetByCat += budgetRepo.GetBudgetLimitByLimitType(budgetType, month, user); totalSpent += TotalSpentByBudgetCategory(month, user, budgetType); } return(totalBudgetByCat - totalSpent); }
public Dictionary <string, float> HighestSavings(string user) { var category = 0; var mostSaved = 0.0f; var categoryStr = ""; var budgetRepo = new BudgetRepository(_context); for (var month = 1; month < 13; month++) { for (var budgetType = 1; budgetType < 7; budgetType++) { var limit = budgetRepo.GetBudgetLimitByLimitType(budgetType, month, user); var spent = TotalSpentByBudgetCategory(month, user, budgetType); var difference = limit - spent; if (difference > mostSaved) { category = budgetType; mostSaved = difference; } } } var categoryUnderBudget = new Dictionary <string, float>(); switch (category) { case 1: categoryStr = "Grocery | Restaurant"; break; case 2: categoryStr = "Mortgage | Rent"; break; case 3: categoryStr = "Bills | Payments"; break; case 4: categoryStr = "Entertainment"; break; case 5: categoryStr = "Gas | Auto"; break; case 6: categoryStr = "Miscellaneous"; break; } if (mostSaved > 0) { categoryUnderBudget.Add(categoryStr, mostSaved); } else { categoryUnderBudget.Add("No Information", 0); } return(categoryUnderBudget); }