/// <summary>
        /// Validates the update cell request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <exception cref="CannotUpdateCellException">Invalid cell value</exception>
        private void ValidateUpdateCellRequest(int playerBoardId, UpdateCellRequest request)
        {
            if (request.Value == null || (request.Value.Value >= 1 && request.Value.Value <= 9))
            {
                return;
            }

            throw new CannotUpdateCellException("Invalid cell value");
        }
Example #2
0
        public async Task <IHttpActionResult> UpdateCellAsync(int playerBoardId, [FromBody] UpdateCellRequest request)
        {
            try
            {
                var cell = await processService.UpdateCellAsync(playerBoardId, request);

                return(Ok(cell));
            }
            catch (CannotUpdateCellException ex)
            {
                logger.Error(ex, ex.Message);
                return(BadRequest(ex.Message));
            }
        }
        private async Task <CellDbModel> UpdateCellAsync(int playerBoardId, UpdateCellRequest request)
        {
            try
            {
                var cellDb = await cells.SingleAsync(cell => cell.PlayerBoardId == playerBoardId &&
                                                     cell.XCoordinate == request.XCoordinate &&
                                                     cell.YCoordinate == request.YCoordinate);

                if (cellDb.IsConst == true)
                {
                    throw new CannotUpdateCellException("Cell is const");
                }

                cellDb.Value = request.Value;

                await unitOfWork.CommitAsync();

                return(cellDb);
            }
            catch (EntityNotFoundException ex)
            {
                throw new CannotUpdateCellException("Can not find any mathcing cell to update", ex);
            }
        }
        /// <inheritdoc />
        async Task <Cell> IGameProcessService.UpdateCellAsync(int playerBoardId, UpdateCellRequest request)
        {
            var cellDb = await UpdateCellAsync(playerBoardId, request);

            return(mapper.Map <Cell>(cellDb));
        }
        /// <inheritdoc />
        public async Task <BoardStatus> UpdateCellAndGetBoardStatusAsync(int playerBoardId, UpdateCellRequest request)
        {
            var cellDb = await UpdateCellAsync(playerBoardId, request);

            return(await GetBoardStatusAsync(playerBoardId));
        }
Example #6
0
        public async Task <IHttpActionResult> UpdateCellAndGetBoardStatusAsync(int playerBoardId, [FromBody] UpdateCellRequest request)
        {
            try
            {
                var status = await processService.UpdateCellAndGetBoardStatusAsync(playerBoardId, request);

                return(Ok(status));
            }
            catch (CannotUpdateCellException ex)
            {
                logger.Error(ex, ex.Message);
                return(BadRequest(ex.Message));
            }
            catch (BoardNotFoundException ex)
            {
                logger.Error(ex, $"Board with {playerBoardId} can not be found.");
                return(NotFound());
            }
        }
        /// <inheritdoc/>
        public Task <Cell> UpdateCellAsync(int playerBoardId, UpdateCellRequest request)
        {
            ValidateUpdateCellRequest(playerBoardId, request);

            return(validatedService.UpdateCellAsync(playerBoardId, request));
        }
        /// <inheritdoc/>
        public Task <BoardStatus> UpdateCellAndGetBoardStatusAsync(int playerBoardId, UpdateCellRequest request)
        {
            ValidateUpdateCellRequest(playerBoardId, request);

            return(validatedService.UpdateCellAndGetBoardStatusAsync(playerBoardId, request));
        }