public async Task <IActionResult> CreateGlobal(GlobalMoneyTransferViewModel model) { if (!ModelState.IsValid) { model.Accounts = (List <Core.Entities.Account>) await _accountService.GetAccountsAsync( Guid.Parse(GetCurrentUserId())); return(View(model)); } model.ToAccountNumber = model.ToAccountNumber.ToUpperInvariant(); var fromAccount = await _accountService.GetAccountAsync(model.AccountId.Value, true); Account toAccount = null; if (model.PaymentTypeId == 1) { toAccount = await _accountService.GetAccountByNumberAsync(model.ToAccountNumber, true); } else { if (!_cardHelper.CheckLuhn(model.ToAccountNumber)) { ModelState.AddModelError("ToAccountNumber", "This credit card is not valid"); model.Accounts = (List <Account>) await _accountService.GetAccountsAsync( Guid.Parse(GetCurrentUserId())); return(View(model)); } toAccount = await _accountService.GetAccountByCardNumberAsync(_cryptoHelper.Hash(model.ToAccountNumber), true); } if (toAccount == null) { ModelState.AddModelError("ToAccountNumber", model.PaymentTypeId == 1 ? "This account does not exist" : "This credit card does not exist"); model.Accounts = (List <Account>) await _accountService.GetAccountsAsync( Guid.Parse(GetCurrentUserId())); return(View(model)); } var currency = await _currencyService.Convert(fromAccount.Currency.Code, toAccount.Currency.Code, model.Amount); await _transactionService.CreateTransactionAsync(fromAccount, toAccount, currency.Rate, model.Amount, model.Description, fromAccount.Currency.Code, toAccount.Currency.Code); return(RedirectToHome()); }
public async Task <IActionResult> CreateGlobal() { var accounts = (List <Core.Entities.Account>) await _accountService.GetAccountsAsync(Guid.Parse(GetCurrentUserId())); var model = new GlobalMoneyTransferViewModel() { Accounts = accounts }; return(View(model)); }