예제 #1
0
        public ActionResult AddCategory(CategoryInputModel model)
        {
            if (ModelState.IsValid)
            {
                var category = new Category(model.Name, CurrencyTools.GetCurrency(model.Currency), model.PlannedAmount);
                _service.AddCategory(category);
                return(GetCategories());
            }

            return(new HttpStatusCodeResult(422));
        }
예제 #2
0
        public ActionResult AddIncome(IncomeInputModel model)
        {
            if (ModelState.IsValid)
            {
                var income  = new Income(model.Name, CurrencyTools.GetCurrency(model.Currency), model.PlannedAmount);
                var newItem = _service.AddIncome(income).MapToIncomeOutputModel();;
                return(PartialView("_income", newItem));
            }

            return(new HttpStatusCodeResult(422));
        }
예제 #3
0
        public ActionResult AddTransaction(TransactionInputModel model)
        {
            if (ModelState.IsValid)
            {
                dynamic from = null;
                switch (model.FromType)
                {
                case TransactionItemType.Wallet:
                    from = _service.GetWallet(model.FromId);
                    break;

                case TransactionItemType.Income:
                    from = _service.GetIncome(model.FromId);
                    break;
                }

                dynamic to = null;
                switch (model.ToType)
                {
                case TransactionItemType.Wallet:
                    to = _service.GetWallet(model.ToId);
                    break;

                case TransactionItemType.Category:
                    to = _service.GetCategory(model.ToId);
                    break;
                }

                if (from == null)
                {
                    throw new ArgumentException($"Cannot find {model.FromType} with id={model.FromId}");
                }

                if (to == null)
                {
                    throw new ArgumentException($"Cannot find {model.ToType} with id={model.ToId}");
                }

                var transaction = new Transaction(from, to, model.Amount, CurrencyTools.GetCurrency(model.Currency), model.Date, model.Comment);

                var newItem = _service.AddTransaction(transaction).MapToTransactionOutputModel();

                return(PartialView("_transaction", newItem));
            }

            return(new HttpStatusCodeResult(422));
        }
예제 #4
0
        public ActionResult AddWallet(WalletInputModel model)
        {
            if (ModelState.IsValid)
            {
                Wallet wallet;

                if (model.IsCreditCard)
                {
                    wallet = new Wallet(model.Name, model.Balance, CurrencyTools.GetCurrency(model.Currency), model.Overdraft);
                }
                else
                {
                    wallet = new Wallet(model.Name, model.Balance, CurrencyTools.GetCurrency(model.Currency));
                }
                var newItem = _service.AddWallet(wallet).MapToWalletOutputModel();


                return(PartialView("_wallet", newItem));
            }

            return(new HttpStatusCodeResult(422));
        }