/// <summary> /// API method that takes in the sudoku board request from client and /// returns sudoku board response with appropriate status code and error message (if any). /// </summary> /// <param name="request"></param> /// <returns>SudokuSolverResponse</returns> public SudokuSolverResponse Solve(SudokuSolverRequest request) { var response = new SudokuSolverResponse { Board = request.Board }; try { if (sudokuSolver.Solve(request.Board)) { response.Status = SudokuSolverResponseStatus.Success; } else { response.Status = SudokuSolverResponseStatus.NotSolved; response.ErrorMessage = "Board could not be solved with the given inputs."; } } catch (BoardInvalidException ex) { response.Status = SudokuSolverResponseStatus.Error; response.ErrorMessage = ex.Message; } catch (Exception ex) { logger.Error(ex); response.Status = SudokuSolverResponseStatus.Error; response.ErrorMessage = "Something unexpected happened. Please try again and if error persists contact admin."; } return(response); }
/// <summary> /// Generates the UI viewmodel from the response received from the sudokusolver service. /// </summary> /// <param name="response"></param> /// <returns></returns> public static SudokuSolverViewModel ToViewModel(this SudokuSolverResponse response) { return(new SudokuSolverViewModel { Board = response.Board.ToStringBoard(), ErrorMessage = response.ErrorMessage }); }