public ActionResult AddBudgetItem(EditBudgetItemViewModel vm, bool isDone) { ViewBag.Title = "Add Budget Item"; var budgets = FinancialPlannerRepository.GetBudgets().Where(m => m.Username == User.Identity.Name); vm.Budgets = SetViewModelsService.SetBudgetViewModels(budgets); if (vm.SelectedBudgetId == NotSelected) { ModelState.AddModelError("SelectedBudgetId", "Budget must be selected"); } if (!ModelState.IsValid) { return(PartialView("EditBudgetItem", vm)); } ViewBag.Title = "Edit Budget Item"; var budgetItem = new BudgetItem(); if (vm.BudgetItemId == 0) { budgetItem = BudgetService.AddBudgetItem(vm); ModelState.Remove("BudgetItemId"); vm.BudgetItemId = budgetItem.Id; return(PartialView("EditBudgetItem", vm)); } return(isDone ? RedirectToAction("Index", new { budgetId = budgetItem.BudgetId, budgetItemId = budgetItem.Id }) : EditBudgetItem(vm, false)); }
public EditExpenseTransactionViewModel MapEditTransactionViewModelForEdit(int id, int expenseId, string username) { var transaction = FinancialPlannerRepository.GetTransactions() .FirstOrDefault(m => m.Id == id); if (transaction == null) { return(null); } var expenses = FinancialPlannerRepository.GetExpenses().Where(m => m.Username == username); var accounts = FinancialPlannerRepository.GetAccounts() .Where(m => m.UserName == username); var budgets = FinancialPlannerRepository.GetBudgets() .Where(m => m.Username == username).ToList(); var vm = new EditExpenseTransactionViewModel { Accounts = SetViewModelsService.SetAccountViewModels(accounts), ExpenseTransactionId = transaction.Id, Amount = transaction.Amount, IsWithdrawal = transaction.IsWithdrawal, Name = transaction.Name, PaymentDate = transaction.PaymentDate, SelectedExpenseId = expenseId != 0 ? expenseId : 0, OldExpenseId = expenseId != 0 ? expenseId : 0, WasWithdrawal = transaction.IsWithdrawal, OldAmount = transaction.Amount, Budgets = SetViewModelsService.SetBudgetViewModels(budgets), Expenses = SetViewModelsService.SetExpenseViewModels(expenses), SelectedAccountId = transaction.AccountId, SelectedBudgetItemId = transaction.BudgetItemId }; if (budgets.Any()) { var budgetIds = budgets.Select(m => m.Id); var budgetItems = FinancialPlannerRepository.GetBudgetItems().Where(m => budgetIds.Contains(m.BudgetId)); vm.BudgetItems = SetViewModelsService.SetBudgetItemViewModels(budgetItems); } var budgetItemForExpense = FinancialPlannerRepository.GetBudgetItems().FirstOrDefault(m => m.Id == transaction.BudgetItemId); if (budgetItemForExpense != null) { vm.SelectedBudgetId = budgetItemForExpense.BudgetId; } return(vm); }
public EditTransactionViewModel MapEditTransactionViewModelForEdit(int id, int accountId, string username) { var transaction = FinancialPlannerRepository.GetTransactions() .FirstOrDefault(m => m.Id == id); if (transaction == null) { return(null); } var accounts = FinancialPlannerRepository.GetAccounts() .Where(m => m.UserName == username); var budgets = FinancialPlannerRepository.GetBudgets() .Where(m => m.Username == username).ToList(); var expenses = FinancialPlannerRepository.GetExpenses().Where(m => m.Username == username); var vm = new EditTransactionViewModel { Accounts = SetViewModelsService.SetAccountViewModels(accounts), AccountTransactionId = transaction.Id, Amount = transaction.Amount, IsWithdrawal = transaction.IsWithdrawal, Name = transaction.Name, PaymentDate = transaction.PaymentDate, SelectedAccountId = accountId != 0 ? accountId : 0, OldAccountId = accountId != 0 ? accountId : 0, WasWithdrawal = transaction.IsWithdrawal, OldAmount = transaction.Amount, Budgets = SetViewModelsService.SetBudgetViewModels(budgets), Expenses = SetViewModelsService.SetExpenseViewModels(expenses) }; if (transaction.BudgetItemId != null && transaction.BudgetItemId > 0) { SetBudgetItemsForViewModel(transaction, vm); } SetSelectedExpenseForViewModel(transaction, vm); return(vm); }
public BudgetIndexViewModel MapBudgetIndexViewModel(string username) { var budgets = FinancialPlannerRepository.GetBudgets() .Where(m => m.Username == username); var vm = new BudgetIndexViewModel { Budgets = SetViewModelsService.SetBudgetViewModels(budgets) }; return(vm); }