public async Task <AllBrokerData> SellStock(BrokerInfo brokerInfo) { var playerBrokerAccount = cache.Get <AllBrokerData>(brokerInfo.PlayerName + "_Broker"); if (playerBrokerAccount == null) { throw new Exception("No broker account exists for provided player"); } var playerBankAccount = cache.Get <AllBankRecords>(brokerInfo.PlayerName + "_Bank"); var turn = cache.Get <Clock>(brokerInfo.PlayerName + "_Clock"); var totalPrice = brokerInfo.StockPrice * brokerInfo.Quantity; var bankTransaction = new BankTransaction(); bankTransaction.PlayerName = playerBankAccount.Accounts.PlayerName; bankTransaction.Price = totalPrice; bankTransaction.Transceiver = brokerInfo.Sector; bankTransaction.Turn = turn.PlayerTurn + 1; await bankService.Deposit(bankTransaction); var brokerRecords = new AllBrokerData() { }; brokerRecords = playerBrokerAccount; brokerInfo.Status = Constants.sellStock; brokerRecords.BrokerInfos.Add(brokerInfo); cache.Set(brokerInfo.PlayerName + "_Broker", brokerRecords, Constants.cacheTime); return(brokerRecords); }
//[ValidateAntiForgeryToken] public IActionResult Deposit(IndexViewModel viewModel) { //if (ModelState.IsValid) //{ // _bankRepository.Deposit(viewModel.AccountNo, viewModel.Amount); // return View(nameof(Index), new IndexViewModel // { // AccountNo = viewModel.AccountNo, // Amount = viewModel.Amount, // Balance = viewModel.Balance // }); //} bool depositSucceded = _bankService.Deposit(viewModel.AccountNo, viewModel.Amount); if (depositSucceded == true) { Account currentAccount = _bankRepository.GetAccountById(viewModel.AccountNo); ViewBag.Message = ("You have successfully made a deposit!"); return(View(nameof(Index), new IndexViewModel { AccountNo = viewModel.AccountNo, Amount = viewModel.Amount, Balance = currentAccount.Balance })); } //else //{ // ViewBag.Message = ("Deposit has not succeeded!"); //} return(RedirectToAction("Index", new { message = "AccountNo doesnt exist. Deposit has not succeeded" })); }
public void RunBankService(IBankService bankService, bool hasLock) { int expectedBalance = 500; if (hasLock) { Console.WriteLine("-------System with a LOCK mechanism----------"); } else { Console.WriteLine("-------System without LOCK mechanism----------"); } Console.WriteLine("Account initialized with $500."); //Create multiple threads in an array Thread[] threads = new Thread[11]; //Set different tasks to thread for (int i = 0; i < threads.Length; i++) { threads[i] = new Thread(() => { int value = r.Next(-500, 500); if (value > 0) { bankService.Deposit(value); expectedBalance += value; } else { if (bankService.Withdraw(0 - value)) { expectedBalance += value; } } }); threads[i].Name = i.ToString(); } //Start all the threads one by one for (int i = 0; i < threads.Length; i++) { threads[i].Start(); } //Join threads to allow continue the parent thread foreach (Thread thread in threads) { thread.Join(); } //Display expected and actual values Console.WriteLine("-----------------------------------------------"); Console.WriteLine($"Expected Balance = {expectedBalance}"); Console.WriteLine($"Actual Balance = {bankService.BalanceQuery()}"); Console.WriteLine(""); }
public async Task <Account> Deposit() { var deposit = new Transaction { Id = "17", Amount = 99m }; var result = await _bankService.Deposit(deposit, _cts.Token); return(result); }
public void Deposit_ValidValue_ValidResult() { IBankService service = GetKernel(); service.NewAccount(1, 1000m, 1); List <AccountBll> storage = service.AllAccount().ToList(); AccountBll temp = storage.Find(item => item.PersoneId == 1); service.Deposit(1000m, temp); Assert.AreEqual(2000m, temp.Balance); }
public void DepositTest() { int accountNumber = 13020, customerNumber = 1005; decimal amount = 888.8M, expectedAmount = 1502M; var expectedResponse = BankResponse.Success; var actualResponse = _service.Deposit(accountNumber, amount); Assert.AreEqual(expectedAmount, GetAccountBalance(customerNumber, accountNumber)); Assert.AreEqual(expectedResponse, actualResponse); }
public async Task <AllBrokerData> SellStock(BrokerInfo brokerInfo) { var stockbuy = new StockMarketService(); var markets = cache.Get <List <AllStockMarketRecords> >(Constants.marketData); var playerBrokerAccount = cache.Get <AllBrokerData>(brokerInfo.PlayerName + "_Broker"); if (playerBrokerAccount == null) { throw new Exception("No broker account exists for provided player"); } var playerBankAccount = cache.Get <AllBankRecords>(brokerInfo.PlayerName + "_Bank"); var turn = cache.Get <Clock>(brokerInfo.PlayerName + "_Clock"); var totalPrice = brokerInfo.StockPrice * brokerInfo.Quantity; var bankTransaction = new BankTransaction(); bankTransaction.PlayerName = playerBankAccount.Accounts.PlayerName; bankTransaction.Price = totalPrice; bankTransaction.Transceiver = brokerInfo.Sector; bankTransaction.Turn = turn.PlayerTurn + 1; await bankService.Deposit(bankTransaction); var brokerRecords = new AllBrokerData() { }; brokerRecords = playerBrokerAccount; brokerInfo.Status = Constants.sellStock; brokerInfo.IsAvailable = false; brokerRecords.BrokerInfos.Add(brokerInfo); foreach (var item in brokerRecords.BrokerInfos) { if (item.Sector == brokerInfo.Sector && item.Stock == brokerInfo.Stock && item.Quantity == brokerInfo.Quantity && item.Status == Constants.boughtStock) { item.IsAvailable = false; } } cache.Set(brokerInfo.PlayerName + "_Broker", brokerRecords, Constants.cacheTime); TurnChange(); var CompaniesList = await GetStocks(brokerInfo.Stock); stockbuy.PriceUpdate(brokerInfo, CompaniesList, markets, "Sell"); return(brokerRecords); }
/// <summary> /// Withdraw from wallet, deposit to bank /// </summary> /// <returns></returns> public async Task <WalletDTO> Withdraw(string jmbg, string pass, decimal amount) { try { await UnitOfWork.BeginTransactionAsync(); var wallet = await UnitOfWork.WalletRepository.GetFirstOrDefaultWithIncludes(w => w.JMBG == jmbg); ValidateWallet(wallet, jmbg, pass); if (wallet.IsBlocked) { throw new WalletServiceException("Wallet je blokiran!", "Withdraw: Wallet is blocked!"); } decimal thisMonthWithdrawSum = await UnitOfWork.TransactionRepository .GetTransactionSumByTransactionsTypeThisMonth(wallet.Id, TransactionType.Withdraw); if (thisMonthWithdrawSum + amount > MaxWithdraw) { throw new WalletServiceException("Vi ste terorista!", "Withdraw: Max amount of withdraw exceeded this month"); } Transaction transaction = new Transaction(wallet.Id, amount, TransactionType.Withdraw); wallet.Withdraw(transaction.Amount); await BankService.Deposit(wallet.JMBG, wallet.PIN, amount); await UnitOfWork.WalletRepository.Update(wallet); await UnitOfWork.TransactionRepository.Insert(transaction); await UnitOfWork.SaveChangesAsync(); await UnitOfWork.CommitTransactionAsync(); return(new WalletDTO(wallet)); } catch (Exception e) { await UnitOfWork.RollbackTransactionAsync(); throw e; } }
public ActionResult Deposit(BankViewModel account) { if (!ModelState.IsValid) { return(View(account)); } try { _service.Deposit(account.Id, account.Balance); return(RedirectToAction("History", new { id = account.Id })); } catch (Exception e) { _log.Error("Error depositing to account: ", e); throw; } }
public AccountDTO Deposit(long accountId, double amount) { try { Account account = _service.GetAccountById(accountId); if (account == null) { throw new BankException("The Account does not exist"); } _service.Deposit(account, amount); _service.Save(); return(account.ToDTO()); } catch (BankException) { throw; } }
public IActionResult Deposit(Transaction transfer) { if (ModelState.IsValid) { var response = _service.Deposit(transfer.AccountNumber, transfer.Amount); if (response == BankResponse.NoAccount) { ModelState.AddModelError(nameof(Transaction.AccountNumber), "The account does not exist"); } if (ModelState.IsValid) { return(View("TransactionSuccess", _service.GetAccountBalance(transfer.AccountNumber))); } } return(View("Index", transfer)); }
public IHttpActionResult Deposit([FromBody] decimal amount) { var user = UserManager.FindById(User.Identity.GetUserId()); if (user == null) { return(BadRequest()); } var result = _service.Deposit(user.Id, amount); if (result.Status != BankRequestStatus.Done) { return(BadRequest(result.Message)); } else { return(Ok(result.Message)); } }
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 async Task <IHttpActionResult> Deposit(BankTransaction transaction) { return(Ok(await bankService.Deposit(transaction))); }