Beispiel #1
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));
        }
Beispiel #2
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));
        }
 private static void BuildCurrencyCodeCache()
 {
     if (!GlobalCachingProvider.Instance.FindItem(ImperaturGlobal.CurrencyCodeCache))
     {
         GlobalCachingProvider.Instance.AddItem(ImperaturGlobal.CurrencyCodeCache, new CurrencyCodeCache(
                                                    CurrencyTools.GetCurrencies().Select(
                                                        c => new CurrencyInfoCache()
         {
             Currency = c
         }).ToArray()
                                                    ));
     }
 }
Beispiel #4
0
        public static IncomeOutputModel MapToIncomeOutputModel(this Income income)
        {
            IncomeOutputModel model = new IncomeOutputModel()
            {
                Name          = income.Name,
                Balance       = income.Balance,
                Currency      = CurrencyTools.GetCurrencySymbol(income.Currency),
                PlannedAmount = income.PlannedAmount,
                Id            = income.Id
            };

            return(model);
        }
Beispiel #5
0
        public static WalletOutputModel MapToWalletOutputModel(this Wallet wallet)
        {
            var model = new WalletOutputModel()
            {
                Name         = wallet.Name,
                Id           = wallet.Id,
                Balance      = wallet.Balance,
                Overdraft    = wallet.Overdraft,
                IsCreditCard = wallet.IsCreditCard,
                Currency     = CurrencyTools.GetCurrencySymbol(wallet.Currency),
            };

            return(model);
        }
Beispiel #6
0
        public ActionResult Index()
        {
            ViewBag.CurrencyList = CurrencyTools.GetCurrencyList().ConvertSelectListItems();

            MainPageOutputModel model = new MainPageOutputModel
            {
                Categories   = _service.GetAllCategories().Select(x => x.MapToCategoryOutputModel()),
                Wallets      = _service.GetAllWallets().Select(x => x.MapToWalletOutputModel()),
                Incomes      = _service.GetAllIncomes().Select(x => x.MapToIncomeOutputModel()),
                Transactions = _service.GetAllTransactions().Select(x => x.MapToTransactionOutputModel())
            };

            return(View(model));
        }
        public static TransactionOutputModel MapToTransactionOutputModel(this Transaction transaction)
        {
            TransactionOutputModel model = new TransactionOutputModel()
            {
                Amount   = transaction.Amount,
                Comment  = transaction.Comment,
                Date     = transaction.Date,
                From     = transaction.From.Name,
                To       = transaction.To.Name,
                Currency = CurrencyTools.GetCurrencySymbol(transaction.Currency),
                Id       = transaction.Id
            };

            return(model);
        }
Beispiel #8
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));
        }
        private void StartTransaction()
        {
            double fromAmount = Amount, toAmount = Amount;

            if (From.Currency != Currency || To.Currency != Currency)
            {
                if (From.Currency != Currency)
                {
                    fromAmount = CurrencyTools.Convert(Amount, From.Currency, Currency);
                }

                if (To.Currency != Currency)
                {
                    toAmount = CurrencyTools.Convert(Amount, To.Currency, Currency);
                }
            }

            From.DecreaseBalance(fromAmount);
            To.IncreaseBalance(toAmount);
        }
Beispiel #10
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));
        }
Beispiel #11
0
 public static void PreloadStaticData()
 {
     CurrencyTools.GetCultureInfoFromIso("GBP");
 }
Beispiel #12
0
 public ActionResult GetCurrencyList()
 {
     return(Json(CurrencyTools.GetCurrencyList().ConvertSelectListItems()));
 }