public void DoTransfer(TransferBankCloudInputModel model, Account grantAccount, Account receiverAccount) { grantAccount.Balance -= model.Amount; if (receiverAccount.CurrencyId != grantAccount.CurrencyId) { ExchangeRate rateFromTo = Fixer .Rate(grantAccount.Currency.IsoCode, receiverAccount.Currency.IsoCode); var convertAmmount = rateFromTo.Convert((double)model.Amount); receiverAccount.Balance += (decimal)convertAmmount; model.ConvertedAmount = (decimal)convertAmmount; } else { receiverAccount.Balance += model.Amount; model.ConvertedAmount = model.Amount; } Transfer transfer = this.mapper.Map <Transfer>(model); transfer.ForeignAccountId = receiverAccount.Id; transfer.Date = DateTime.UtcNow; transfer.Completed = DateTime.UtcNow; transfer.Type = TransferType.BankCloud; transfer.Status = TransferStatus.Approved; transfer.BalanceType = BalanceType.Negative; this.context.Transfers.Add(transfer); this.context.SaveChanges(); }
public IActionResult Transfer(TransferBankCloudInputModel model) { if (!ModelState.IsValid) { return(this.View(model)); } var grantAccount = this.accountsService.GetAccountById(model.Id); if (grantAccount.Balance < model.Amount) { this.TempData["error"] = GlobalConstants.INSUFFICIENT_FUNDS; return(this.View(model)); } var receiverAccount = this.accountsService.GetAccountByIban(model.IBAN); if (receiverAccount == null || grantAccount.Id == receiverAccount.Id) { this.TempData["error"] = GlobalConstants.MISSING_IBAN_ACCOUNT; return(this.View(model)); } this.transferService.DoTransfer(model, grantAccount, receiverAccount); return(this.Redirect("/Accounts/Index")); }