示例#1
0
        public IActionResult SaveBudget(CreateBudgetView viewModel)
        {
            if (ModelState.IsValid)
            {
                var lineItem = _budgetManager.GetByLineItemId(viewModel.Economic);

                if (lineItem != null)
                {
                    viewModel.LineItemList = _itemManager.GetListItems();

                    ModelState.AddModelError("Economic", CreateBudgetView.EconomicExistError);

                    return(View("CreateBudget", viewModel));
                }

                _budgetManager.Save(viewModel);

                TempData["AlertMessage"] = "Your budget was saved successfully.";

                return(RedirectToAction("Index"));
            }

            viewModel.LineItemList = _itemManager.GetListItems();

            return(View("CreateBudget", viewModel));
        }
示例#2
0
        public Budget Save(CreateBudgetView viewModel)
        {
            var budget = new Budget
            {
                TransactionDate = viewModel.TransactionDate,
                Description     = viewModel.Description,
                Amount          = decimal.Parse(viewModel.Amount),
                EconomicId      = viewModel.Economic,
                Type            = BudgetStatusType.DRAFT,
            };

            if (viewModel.Id != Guid.Empty)
            {
                budget.Id = viewModel.Id;
                _unitOfWork.BudgetsRepository.Update(budget);

                var history = new BudgetAmendHistory
                {
                    Budget          = budget,
                    Amount          = decimal.Parse(viewModel.PreviousAmount),
                    TransactionDate = DateTime.Now.ToString(DateFormatKey.Default)
                };

                _unitOfWork.BudgetAmendHistoriesRepository.Insert(history);
            }
            else
            {
                _unitOfWork.BudgetsRepository.Insert(budget);
            }


            _unitOfWork.SaveChanges();

            return(budget);
        }
示例#3
0
        public IActionResult CreateBudget()
        {
            var viewModel = new CreateBudgetView
            {
                LineItemList    = _itemManager.GetListItems(),
                TransactionDate = DateTime.Now.ToString(DateFormatKey.Default),
            };

            return(View(viewModel));
        }
示例#4
0
        public IActionResult AmendBudget(string budgetId)
        {
            var budget = _budgetManager.GetById(budgetId);

            if (budget == null)
            {
                return(RedirectToAction("Index"));
            }

            var viewModel = new CreateBudgetView
            {
                Id = budget.Id,
                TransactionDate = budget.TransactionDate,
                Description     = budget.Description,
                Economic        = budget.EconomicId,
                Amount          = budget.Amount.ToString(AmountFormatKey.Default),
                PreviousAmount  = budget.Amount.ToString(AmountFormatKey.Default),
                LineItemList    = _itemManager.GetListItems(),
            };

            return(View("CreateBudget", viewModel));
        }