Ejemplo n.º 1
0
        public ActionResult EditBudgetItem(EditBudgetItemViewModel vm, bool isDone)
        {
            ViewBag.Title = "Edit 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");
                return(PartialView("EditBudgetItem", vm));
            }

            var saved = BudgetService.EditBudgetItem(vm);

            if (!saved)
            {
                return(View("Error"));
            }

            if (isDone)
            {
                return(RedirectToAction("Index", new { budgetId = vm.SelectedBudgetId, budgetItemId = vm.BudgetItemId }));
            }

            return(PartialView("EditBudgetItem", vm));
        }
Ejemplo n.º 2
0
        public EditBudgetItemViewModel MapEditBudgetItemViewModel(int id, string username)
        {
            var budgetItem = FinancialPlannerRepository.GetBudgetItems()
                             .FirstOrDefault(m => m.Id == id);
            var budgets = FinancialPlannerRepository.GetBudgets()
                          .Where(m => m.Username == username);

            if (budgetItem == null)
            {
                return(null);
            }

            var vm = new EditBudgetItemViewModel
            {
                BudgetItemId     = budgetItem.Id,
                Name             = budgetItem.Name,
                Amount           = budgetItem.Amount,
                SelectedBudgetId = budgetItem.BudgetId,
                Budgets          = budgets.Select(m => new BudgetViewModel
                {
                    Id        = m.Id,
                    Name      = m.Name,
                    StartDate = m.StartDate,
                    EndDate   = m.EndDate
                }).ToList()
            };

            return(vm);
        }
Ejemplo n.º 3
0
        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 ActionResult EditItem(EditBudgetItemViewModel model)
 {
     if (ModelState.IsValid)
     {
         var budgetItem = _budgetManager.GetItem(model.Id);
         budgetItem.Amount     = model.Amount;
         budgetItem.CategoryId = model.CategoryId;
         _budgetManager.EditItem(budgetItem);
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 5
0
        public EditBudgetItemViewModel MapEditBudgetItemViewModelForAdd(string username)
        {
            var budgets = FinancialPlannerRepository.GetBudgets()
                          .Where(m => m.Username == username);

            var vm = new EditBudgetItemViewModel
            {
                Budgets = SetViewModelsService.SetBudgetViewModels(budgets)
            };

            return(vm);
        }
        public PartialViewResult EditBudgetItemModal(int id)
        {
            var budgetItem = _budgetManager.GetItem(id);
            var categories = _categoryManager.GetAll(User.Identity.GetHouseholdId().Value);
            var model      = new EditBudgetItemViewModel()
            {
                Amount             = budgetItem.Amount,
                CategoryId         = budgetItem.CategoryId,
                CategorySelectList = new SelectList(categories, "Id", "Name", budgetItem.CategoryId)
            };

            return(PartialView(model));
        }
Ejemplo n.º 7
0
        public BudgetItem AddBudgetItem(EditBudgetItemViewModel vm)
        {
            var budgetItem = new BudgetItem
            {
                Name     = vm.Name,
                Amount   = vm.Amount,
                BudgetId = vm.SelectedBudgetId,
                Balance  = vm.Amount
            };

            FinancialPlannerRepository.AddBudgetItem(budgetItem);
            FinancialPlannerRepository.Save();

            return(budgetItem);
        }
Ejemplo n.º 8
0
        public bool EditBudgetItem(EditBudgetItemViewModel vm)
        {
            var budgetItem = FinancialPlannerRepository.GetBudgetItems().FirstOrDefault(m => m.Id == vm.BudgetItemId);

            if (budgetItem == null)
            {
                return(false);
            }

            var oldBudgetBalance = budgetItem.Balance;
            var oldBudgetAmount  = budgetItem.Amount;

            budgetItem.Name     = vm.Name;
            budgetItem.Amount   = vm.Amount;
            budgetItem.BudgetId = vm.SelectedBudgetId;
            budgetItem.Balance  = oldBudgetBalance + (vm.Amount - oldBudgetAmount);

            FinancialPlannerRepository.Save();

            return(true);
        }