Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> AddBudgetItem(int categoryId, int budgetId, decimal amount)
        {
            try
            {
                return(Ok(await _budgetService.AddBudgetItem(categoryId, budgetId, amount)));
            } catch (Exception ex)
            {
                _logService.AddErrorWinEventLog(ex);
                _securityService.HideErrorTime();

                return(StatusCode(HttpStatusCode.InternalServerError));
            }
        }