public IActionResult Get([FromQuery] GridCellMapper gridMapper) { try { //First Convert from the mapped valudes to actual numeric grid values GridCellPosition position = new GridCellPosition(gridMapper.GetNumericColumn(), gridMapper.GetNumericRow()); //Check that the position is valid if (_shapeProcessor.ValidateGridCellPosition(position)) { //Yep, all's Ok - go get the shape IShape triangle = _shapeProcessor.GetShape(position); return(Ok(triangle)); } else { //Not found return(NotFound()); } } catch (ArgumentOutOfRangeException ex) { //Out of range - means not found _logger.LogError(ex.Message); return(NotFound()); } catch (Exception ex) { _logger.LogError(ex.Message); } //Something has gone wrong. return(BadRequest()); }
public IActionResult Post([FromBody] Triangle triangle) { try { //Check that the triangle is valid if (_shapeProcessor.ValidateShape(triangle)) { //Yep, all's Ok GridCellPosition position = _shapeProcessor.GetGridCellPosition(triangle); //Convert from numeric grid, to mapped grid values GridCellMapper gridMapper = new GridCellMapper(); gridMapper.SetGridMappedValues(position.Row, position.Column); return(Created(Request.Path.ToString(), gridMapper)); } else { //Not found return(NotFound()); } } catch (ArgumentOutOfRangeException ex) { //Out of range - means not found _logger.LogError(ex.Message); return(NotFound()); } catch (Exception ex) { _logger.LogError(ex.Message); } //Something has gone wrong. return(BadRequest()); }
public void TestSetup() { _gridCellMapper = new GridCellMapper(); }