public void Run() { Random random = new Random(); List <int> badIdForSeller = new List <int>(); TransactionInfo transactionInfo = new TransactionInfo(); var clients = this.showDbInfoService.GetAllClients(); do { transactionInfo.BuyerId = clients.ElementAt(random.Next(0, clients.Count - 1)).Id; badIdForSeller.Add(transactionInfo.BuyerId); transactionInfo.SellerId = clients.ElementAt(random.Next(0, clients.Count - 1)).Id; if (transactionInfo.BuyerId == transactionInfo.SellerId) { do { transactionInfo.SellerId = clients.ElementAt(random.Next(0, clients.Count - 1)).Id; if ((showDbInfoService.GetAccountByClientId(transactionInfo.SellerId) == null) && (showDbInfoService.GetAccountByClientId(transactionInfo.SellerId).Stocks.Count == 0)) { badIdForSeller.Add(transactionInfo.SellerId); } } while (badIdForSeller.Contains(transactionInfo.SellerId)); } var sellersAccount = this.showDbInfoService.GetAccountByClientId(transactionInfo.SellerId); var StockForSell = showDbInfoService.GetStocksOfClientByAccountId(sellersAccount.AccountId).ElementAt(random.Next(0, sellersAccount.Stocks.Count - 1)); transactionInfo.TypeOfStock = StockForSell.TypeOfStocks; transactionInfo.QuantityOfStocks = random.Next(1, StockForSell.quantityOfStocks); this.tradingService.MakeATrade(transactionInfo); Thread.Sleep(10000); } while (!this.showDbInfoService.GetClientsInBlackZone().Any()); }
private bool ShowInfoMenu() { string userInput; inputOutputModule.ClearMenu(); inputOutputModule.WriteOutput(phraseProvider.GetPhrase(gameSettings.LangPackName, KeysForPhrases.ShowClients)); inputOutputModule.WriteOutput(phraseProvider.GetPhrase(gameSettings.LangPackName, KeysForPhrases.ShowStocksOfClients)); inputOutputModule.WriteOutput(phraseProvider.GetPhrase(gameSettings.LangPackName, KeysForPhrases.ShowStockPrice)); inputOutputModule.WriteOutput(phraseProvider.GetPhrase(gameSettings.LangPackName, KeysForPhrases.ShowHistory)); inputOutputModule.WriteOutput(gameSettings.ExitButton); inputOutputModule.WriteOutput(phraseProvider.GetPhrase(gameSettings.LangPackName, KeysForPhrases.ExitKey)); userInput = inputOutputModule.ReadInput(); if (userInput == "1") { inputOutputModule.ClearMenu(); inputOutputModule.WriteOutput("List of clients\n"); foreach (var client in showDbInfoService.GetAllClients()) { inputOutputModule.WriteOutput($"ID: {client.Id} Name: {client.Name} Surname: {client.Surname} Phone: {client.PhoneNumber} Balance: {showDbInfoService.GetAccountByClientId(client.Id).Balance} Zone: {showDbInfoService.GetAccountByClientId(client.Id).Zone}\n"); } } if (userInput == "2") { int prevID = -1; inputOutputModule.ClearMenu(); inputOutputModule.WriteOutput("List of client's stocks\n"); foreach (var stock in showDbInfoService.GetAllStocksOfClient()) { if (stock.AccountForStock.ClientId != prevID) { inputOutputModule.WriteOutput($"ClientID: {stock.AccountForStock.ClientId}\n"); } inputOutputModule.WriteOutput($"Type: {stock.TypeOfStocks} Quantity: {stock.quantityOfStocks}\n"); prevID = stock.AccountForStock.ClientId; } } if (userInput == "3") { inputOutputModule.ClearMenu(); inputOutputModule.WriteOutput("List of stocks prices\n"); foreach (var stock in showDbInfoService.GetAllStockPrice()) { inputOutputModule.WriteOutput($"Type: {stock.TypeOfStock} Price: {stock.PriceOfStock}\n"); } } if (userInput == "4") { inputOutputModule.ClearMenu(); inputOutputModule.WriteOutput("History of transaction\n"); foreach (var history in showDbInfoService.GetFullHistory()) { inputOutputModule.WriteOutput($"Id: {history.Id} BuyerId: {history.BuyerId} SellerId: {history.SellerId} TypeOfStock: {history.TypeOfStock} QuantityOfStocks: {history.QuantityOfStocks} FullPrice: {history.FullPrice}\n"); } } if (userInput == gameSettings.ExitButton) { return(false); } inputOutputModule.ReadKey(); return(true); }