Ejemplo n.º 1
0
        //Poisition a ship
        public async Task <bool> AddShip(ShipAddRequest request)
        {
            bool result = false;
            var  board  = battleshipBoardGame.Board;

            if (board == null)
            {
                response.Message = ResponseMessages.BOARD_NOT_CREATED;
                return(result);
            }


            var serializeRequest = JsonConvert.SerializeObject(request);

            //Sanitize the request.
            if (await serviceHelper.IsRequestValid(request))
            {
                //check Orientation
                if (request.Orientation == nameof(Orientation.Vertical).ToLower())
                {
                    result = await serviceHelper.AddShipVertically(request, board);
                }
                else
                {
                    if (request.Orientation == nameof(Orientation.Horizontal).ToLower())
                    {
                        result = await serviceHelper.AddShipHorizontally(request, board);
                    }
                }
            }
            if (!result)
            {
                logger.LogInformation($"Invalid request for Ship: {serializeRequest}");
            }
            return(result);
        }