public IActionResult Transfer(TransferViewModel vm) { if (ModelState.IsValid) { var isSuccess = _bankService.Transfer(vm.FromAccountId, vm.ToAccountId, vm.Amount); if (isSuccess) { var fromAccount = _bankService.GetAccountById(vm.FromAccountId); var toAccount = _bankService.GetAccountById(vm.ToAccountId); return(View(nameof(Index), new TransferViewModel { FromAccountId = vm.FromAccountId, ToAccountId = vm.ToAccountId, Amount = vm.Amount, FromActualSumString = fromAccount.ActualSum.ToString("C"), ToActualSumString = toAccount.ActualSum.ToString("C") })); } else { ModelState.AddModelError("FromAccountId", "Det finns inte tillräckligt med pengar på ditt konto."); } } return(View(nameof(Index), vm)); }
public IHttpActionResult Details(Int64 accountId) { var account = _bankService.GetAccountById(accountId); if (account == null) { return(NotFound()); } return(OkResult(account)); }
public IActionResult Deposit(IndexViewModel vm) { if (ModelState.IsValid) { try { var isSuccess = _bankService.Deposit(vm.AccountId, vm.Amount); if (isSuccess) { var account = _bankService.GetAccountById(vm.AccountId); return(View(nameof(Index), new IndexViewModel { AccountId = vm.AccountId, Amount = vm.Amount, ActualSumString = account.ActualSum.ToString("C") })); } else { ModelState.AddModelError("AccountId", "Det gick inte att utföra en insättning. Vänligen kontakta banken."); } } catch (AccountNotFoundException e) { ModelState.AddModelError("AccountId", e.Message); } catch (NonPositiveValueException e) { ModelState.AddModelError("Amount", e.Message); } } return(View(nameof(Index), new IndexViewModel { AccountId = vm.AccountId, Amount = vm.Amount, ActualSumString = vm.ActualSumString })); }
public AccountDTO GetAccountDTOById(long id) { return(_service.GetAccountById(id).ToDTO()); }