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");
        }
Пример #2
0
        /// <summary>
        /// Determines if any of the possible bank types appear on screen.
        /// Sets BankBoothCounter to the first match found.
        /// </summary>
        /// <returns>true if any of them do</returns>
        internal bool IdentifyBank()
        {
            Blob booth;

            Screen.ReadWindow();
            foreach (BankLocator bankLocator in PossibleBankTypes)
            {
                if (bankLocator(out booth))
                {
                    BankBoothLocator = bankLocator;
                    return(true);
                }
            }
            return(false);
        }