public void AddAccountTest()
        {
            Account tempAccount = new Account
            {
                _AccountId  = 0,
                _CustomerId = 3,
                _Name       = "American Express",
                _Balance    = 3500.00m,
                _Apr        = 0.199f,
                _MinPay     = 25.00m,
                _Payment    = 100.00m
            };

            _accountDataService.AddAccount(tempAccount);
            var size = _accountDataService.FindAll().Count();

            Assert.AreEqual(11, size);
        }
예제 #2
0
        public IActionResult Create(AccountViewModel viewModel)
        {
            // Check to see if ACCOUNT_ID already exists
            if (_accountData.GetAccountById(viewModel.AccountId) != null)
            {
                ModelState.AddModelError("AccountId", $"Account ID already exists.");
            }

            if (ModelState.IsValid)
            {
                var account = new Account
                {
                    AccountId   = viewModel.AccountId,
                    AccountName = viewModel.AccountName,
                    Level1      = viewModel.Level1,
                    Level2      = viewModel.Level2,
                    Level3      = viewModel.Level3,
                    Level4      = viewModel.Level4,
                    Remarks     = viewModel.Remarks,
                    UserId      = viewModel.UserId
                };

                try
                {
                    _accountData.AddAccount(account);
                    _accountData.Save();
                }
                catch (Exception e)
                {
                    // TODO: Log this exception
                    ModelState.AddModelError(string.Empty, $"ERROR: Unable to save data. Please review your input and try again.");

                    ViewData["NextId"] = viewModel.AccountId;
                    return(View(viewModel));
                }

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["NextId"] = viewModel.AccountId;

            return(View(viewModel));
        }
 public void Post([FromBody] Account account)
 {
     accountDataService.AddAccount(account);
 }