public IHttpActionResult Play(PlayTurnBindingModel model)
        {
            if (model == null)
            {
                this.ModelState.AddModelError("model", "The model is empty");
            }

            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var guidGameId = new Guid(model.GameId);
            var game = this.Data.Games.FirstOrDefault(x => x.Id == guidGameId);
            if (game == null)
            {
                return this.NotFound();
            }

            var userId = this.userIdProvider.GetUserId();
            if (game.PlayerOneId != userId && game.PlayerTwoId != userId)
            {
                return this.BadRequest("You do not play in this game.");
            }

            if ((game.PlayerOneId == userId && game.State == GameState.WonByOne) ||
                game.PlayerTwoId == userId && game.State == GameState.WonByTwo)
            {
                return this.BadRequest("You already won this game.");
            }

            if ((game.PlayerOneId == userId && game.State == GameState.WonByTwo) ||
                game.PlayerTwoId == userId && game.State == GameState.WonByOne)
            {
                return this.BadRequest("You lost this game.");
            }

            if ((game.PlayerOneId == userId && game.State == GameState.TurnTwo) || 
                (game.PlayerTwoId == userId && game.State == GameState.TurnOne))
            {
                return this.BadRequest("It's not your turn.");
            }

            var fieldSideLength = (int)Math.Sqrt(game.Field.Length);
            if (model.PositionX >= fieldSideLength || model.PositionY >= fieldSideLength)
            {
                return this.BadRequest("Invalid position.");
            }

            var fieldPosition = model.PositionX + (model.PositionY * fieldSideLength);
            if (game.Field[fieldPosition] == 'X')
            {
                return this.BadRequest("Position already bombed.");
            }

            var response = "You didn't hit anything.";
            if (game.Field[fieldPosition] == 'S')
            {
                if (game.PlayerOneId == userId)
                {
                    game.PlayerOnePoints++;
                }
                else
                {
                    game.PlayerTwoPoints++;
                }

                response = "You hit a ship. You get one point.";
            }

            var field = new StringBuilder(game.Field);
            field[fieldPosition] = 'X';
            game.Field = field.ToString();
            game.State = game.State == GameState.TurnOne ? GameState.TurnTwo : GameState.TurnOne;

            if (!game.Field.Contains('S'))
            {
                game.State = game.PlayerOnePoints > game.PlayerTwoPoints ? GameState.WonByOne : GameState.WonByTwo;
                response = "You Won.";
            }

            this.Data.SaveChanges();

            return this.Ok(response);
        }
        public IHttpActionResult PlayTurn(PlayTurnBindingModel model)
        {
            if (model == null)
            {
                this.ModelState.AddModelError("model", "The model is empty");
            }

            if (!ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var guidGameId = new Guid(model.GameId);
            var game = this.Data.Games
                .All()
                .FirstOrDefault(x => x.Id == guidGameId);
            if (game == null)
            {
                return this.NotFound();
            }

            var userId = this.userIdProvider.GetUserId();
            if (game.PlayerOneId != userId && game.PlayerTwoId != userId)
            {
                return this.BadRequest("You can't make turn in this game!");
            }

            if ((game.PlayerOneId == userId && game.State == GameState.TurnTwo) ||
                (game.PlayerTwoId == userId && game.State == GameState.TurnOne))
            {
                return this.BadRequest("It's not your turn!");
            }

            var fieldSideLength = (int)Math.Sqrt(game.Field.Length);
            if (model.PositionX >= fieldSideLength || model.PositionY >= fieldSideLength)
            {
                return this.BadRequest("Invalid position!");
            }

            var fieldPosition = model.PositionX + (model.PositionY * fieldSideLength);
            if (game.Field[fieldPosition] == 'X')
            {
                return this.BadRequest("Position already bombed!");
            }

            var field = new StringBuilder(game.Field);
            field[fieldPosition] = 'X';
            game.Field = field.ToString();
            game.State = game.State == GameState.TurnOne ? GameState.TurnTwo : GameState.TurnOne;
            this.Data.SaveChanges();

            return this.Ok();
        }