public static MakeMove FromDTO(long id, DTO.MakeMove dtoCommand) { string notation = dtoCommand.Notation; PieceCode pieceCode; StartSquare start; DestinationSquare destination; if ("RNBQK".Contains(notation.First())) { Enum.TryParse(dtoCommand.Notation.Substring(0, 1), out pieceCode); start = new StartSquare(dtoCommand.Notation.Substring(1, 2)); destination = new DestinationSquare(dtoCommand.Notation.Substring(4, 2)); } else { pieceCode = PieceCode.None; start = new StartSquare(dtoCommand.Notation.Substring(0, 2)); destination = new DestinationSquare(dtoCommand.Notation.Substring(3, 2)); } var move = new Move(pieceCode, start, destination); var result = new MakeMove(id, move); return(result); }
public async Task <IActionResult> MakeMove(long id, [FromBody] DTO.MakeMove dtoCommand) { //if (!ModelState.IsValid) //{ // return BadRequest("not a valid move."); //} try { MakeMove command = DTOMapper.FromDTO(id, dtoCommand); await _makeMoveCommandHandler.HandleCommandAsync(command); return(Ok()); } catch (GameNotFoundException ex) { return(NotFound(ex.Message)); } catch (BusinessRuleViolationException brve) { return(StatusCode(StatusCodes.Status409Conflict, brve.Violations)); } //catch //{ // return StatusCode(501); //} }