コード例 #1
0
        public IActionResult AllExpiredGames()
        {
            // TODO: Refactor with SQL Join Statement
            IList <GameModel>    unformattedCurrentGames = gameDao.GetAllExpiredGames();
            IList <GameAPIModel> formattedGames          = new List <GameAPIModel>();

            foreach (GameModel game in unformattedCurrentGames)
            {
                GameAPIModel gameFormatted = FormatGameToApiModel(game);
                formattedGames.Add(gameFormatted);
            }


            return(new JsonResult(formattedGames));
        }
コード例 #2
0
        public void SellOffStocks()
        {
            //get all games that need to be processed
            IList <GameModel> expiredGames = gameDao.GetAllExpiredGames();

            foreach (GameModel game in expiredGames)
            {
                //find all the users within the game
                IList <UserModel> users = userDao.GetUsersByGame(game.Id);

                foreach (UserModel user in users)
                {
                    //get all the stocks the user owns in a particular game
                    IList <OwnedStocksModel> expiredStocks = ownedHelper.GetOwnedStocksByUserAndGame(user.Id, game.Id);

                    foreach (OwnedStocksModel stock in expiredStocks)
                    {
                        TransactionModel finalTransaction = new TransactionModel()
                        {
                            UserId                = user.Id,
                            GameId                = game.Id,
                            StockSymbol           = stock.StockSymbol,
                            NumberOfShares        = stock.NumberOfShares,
                            TransactionSharePrice = stock.CurrentSharePrice,
                            IsPurchase            = false,
                            NetTransactionChange  = stock.NumberOfShares * stock.CurrentSharePrice
                        };
                        //use transactionDAO to sell all of these stocks

                        transactionDao.AddNewTransaction(finalTransaction);

                        //sell all the stocks a user has
                    }
                }
                gameDao.UpdateTransactionsEndGame(game.Id);
            }
        }