Esempio n. 1
0
        public ResultToken SellStocks(int playerId, StockDetail stock, int quantity, decimal price)
        {
            ResultToken result = null;

            PlayerTransactionsDTO obj = new PlayerTransactionsDTO();

            obj.PlayerId = playerId;
            obj.Stock    = stock;
            obj.Quantity = quantity;
            obj.Price    = price;

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var temp = apiClient.MakePostRequest("api/Broker/SellStocks", obj);
                    result = apiClient.ConvertObjectToToken(temp);
                    if (result != null && result.Success)
                    {
                        result.Data = obj;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(result);
        }
Esempio n. 2
0
        public GameDTO CreateGame(string playerName, int playerCount, bool isPrivate)
        {
            GameDTO returnObj = null;

            GameDTO game = new GameDTO();

            game.CreatedPlayer = playerName;
            game.PlayersCount  = playerCount;
            game.IsPublic      = !isPrivate;

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/Game/CreateGame", game);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result.Success && result.Data != null)
                    {
                        returnObj = JsonConvert.DeserializeObject <GameDTO>(result.Data.ToString());
                    }
                }
            }
            catch (Exception ex) {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(returnObj);
        }
Esempio n. 3
0
        public PlayerDTO CreatePlayer(string playerName, int gameId, string connectionId)
        {
            PlayerDTO returnObj = null;

            JoinRequestModel request = new JoinRequestModel();

            request.PlayerName   = playerName;
            request.GameId       = gameId;
            request.ConnectionId = connectionId;
            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/Game/JoinGame", request);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result.Success && result.Data != null)
                    {
                        returnObj = JsonConvert.DeserializeObject <PlayerDTO>(result.Data.ToString());
                        if (returnObj != null)
                        {
                            var tempAccount = CreateBankAccount(returnObj);
                            if (tempAccount != null)
                            {
                                returnObj.BankAccount = tempAccount;
                            }
                            else
                            {
                                returnObj = null;
                            }
                        }
                    }
                }
            }
            catch (Exception ex) {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(returnObj);
        }
Esempio n. 4
0
        public GameDTO StartGame(int gameId)
        {
            GameDTO game = null;

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/Game/StartGame", gameId);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result.Success && result.Data != null)
                    {
                        game = JsonConvert.DeserializeObject <GameDTO>(result.Data.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }
            return(game);
        }
Esempio n. 5
0
        public List <SectorDTO> GetSectors()
        {
            List <SectorDTO> returnObj = new List <SectorDTO>();

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakeGetRequest("api/game/sectors");
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result.Success && result.Data != null)
                    {
                        returnObj = JsonConvert.DeserializeObject <List <SectorDTO> >(result.Data.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(returnObj);
        }
Esempio n. 6
0
        public List <AIBuySellDetails> GetPlayerAIData(GameDTO gameobj)
        {
            List <AIBuySellDetails> list = null;

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/PlayerAi/GetPlayerAIData", gameobj);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result != null && result.Success)
                    {
                        list = JsonConvert.DeserializeObject <List <AIBuySellDetails> >(result.Data.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(list);
        }
Esempio n. 7
0
        public GameDetailDTO GetGameData(int gameId)
        {
            GameDetailDTO returnObj = new GameDetailDTO();

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakeGetRequest("api/trend?gameId=" + gameId.ToString());
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result.Success && result.Data != null)
                    {
                        returnObj = JsonConvert.DeserializeObject <GameDetailDTO>(result.Data.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(returnObj);
        }
Esempio n. 8
0
        public BankAccountDTO CreateBankAccount(PlayerDTO player)
        {
            BankAccountDTO returnObj = null;

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/Bank/CreateAccount", player);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (result.Success && result.Data != null)
                    {
                        returnObj = JsonConvert.DeserializeObject <BankAccountDTO>(result.Data.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(returnObj);
        }
Esempio n. 9
0
        public bool GameEnded(PlayerDTO winner)
        {
            bool success = true;

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/Game/GameOver", winner);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (!result.Success)
                    {
                        success = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(success);
        }
Esempio n. 10
0
        public bool DisconnectGame(int gameId)
        {
            bool success = true;

            try
            {
                using (APIService apiClient = new APIService())
                {
                    var         temp   = apiClient.MakePostRequest("api/Game/EndGame", gameId);
                    ResultToken result = apiClient.ConvertObjectToToken(temp);
                    if (!result.Success)
                    {
                        success = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger logger = LogManager.GetLogger("excpLogger");
                logger.Error(ex);
            }

            return(success);
        }