コード例 #1
0
        /// <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");
        }
コード例 #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));
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        /// <inheritdoc />
        async Task <Cell> IGameProcessService.UpdateCellAsync(int playerBoardId, UpdateCellRequest request)
        {
            var cellDb = await UpdateCellAsync(playerBoardId, request);

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

            return(await GetBoardStatusAsync(playerBoardId));
        }
コード例 #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());
            }
        }
コード例 #7
0
        /// <inheritdoc/>
        public Task <Cell> UpdateCellAsync(int playerBoardId, UpdateCellRequest request)
        {
            ValidateUpdateCellRequest(playerBoardId, request);

            return(validatedService.UpdateCellAsync(playerBoardId, request));
        }
コード例 #8
0
        /// <inheritdoc/>
        public Task <BoardStatus> UpdateCellAndGetBoardStatusAsync(int playerBoardId, UpdateCellRequest request)
        {
            ValidateUpdateCellRequest(playerBoardId, request);

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