Пример #1
0
        public HttpResponseMessage GetPlayerData()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(null);
            }

            string     userName   = User.Identity.Name;
            PlayerData playerData = PlayerDataSql.GetPlayerData(userName);


            HttpResponseMessage response;

            if (playerData == null)
            {
                response = new HttpResponseMessage();
                response.ReasonPhrase = $"Error processing request: user not found";
                response.StatusCode   = System.Net.HttpStatusCode.BadRequest;
                return(response);
            }

            string json = JsonConvert.SerializeObject(playerData);

            response            = new HttpResponseMessage();
            response.StatusCode = System.Net.HttpStatusCode.OK;
            response.Content    = new StringContent(json);
            return(response);
        }
Пример #2
0
        public HttpResponseMessage GetStationInfo()
        {
            string     steamId    = User.Identity.Name;
            PlayerData playerData = PlayerDataSql.GetPlayerData(steamId);

            if (playerData.StationOpened == 0)
            {
                var negativeResponse = new HttpResponseMessage(HttpStatusCode.BadRequest);
                negativeResponse.ReasonPhrase = "Station is not opened yet";
                return(negativeResponse);
            }
            int     playerId          = playerData.Id;
            Station station           = new Station(playerId);
            string  serializedElement = JsonConvert.SerializeObject(station);
            var     response          = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(serializedElement);
            return(response);
        }