public RedirectToActionResult DoTransaction(int userId, string name, string surname, string accountNo, double value) { var curentUser = _userManager.GetAll(userId).First(); // create beneficiary var beneficiary = new Beneficiary() { Name = name, Surname = surname, Account = accountNo, }; // check if user has enough money if (value > curentUser.Ballance) { throw new Exception("User does not have enuf money"); } // Find Beneficiary bank var benBankId = new BankLocator().GetUserBank(beneficiary.Account); // Set Beneficiary bank id beneficiary.BankId = benBankId; // create transaction var transaction = new Transaction() { Information = "some info that does not exist", ActiveBankId = beneficiary.BankId, BeneficiaryId = beneficiary.Id, UserId = curentUser.Id, TransferedValue = value }; // send transaction to bank var activeBankContext = new ActiveBankDbContext(_connectionString); new BankApi(beneficiary.BankId, activeBankContext, beneficiary).MakeTransaction(); // save beneficiary details in db _beneficiaryManager.SaveBeneficiary(beneficiary); // save transaction details in db _transactionManager.SaveTransaction(transaction); curentUser.Ballance = curentUser.Ballance - value; // save user ballance _userManager.UpdateUser(curentUser); return RedirectToAction("Index", "Home"); }
public BankApi(int bankId, ActiveBankDbContext activeBankDbContext, Beneficiary beneficiary) { _bankId = bankId; _activeBankDbContext = activeBankDbContext; _beneficiary = beneficiary; }