public IActionResult AddBattleShip(BattleshipModel battleshipModel) { try { string username = GetCurrentUserName(); var result = _battleshipGameService .AddBattleship(username, battleshipModel.Ship , battleshipModel.StartPosition, battleshipModel.ShipPlacement); if (result) { return(ResponseMessageHelper.Ok("Ship Added")); } else { return(ResponseMessageHelper.InternalServerError()); } } catch (BattleshipGameException ex) { return(ResponseMessageHelper.BadRequest(ex.Message)); } catch (Exception ex) { //write exception to a error log return(ResponseMessageHelper.InternalServerError()); } }
public async Task <IActionResult> SignIn(User user) { if (!ModelState.IsValid) { return(ResponseMessageHelper.ModelStateInvalid(ModelState)); } var cognito = new AmazonCognitoIdentityProviderClient(_region); var request = new AdminInitiateAuthRequest { UserPoolId = _config.Value.AwsCognitoUserPoolId, ClientId = _config.Value.AwsCognitoAppClientId, AuthFlow = AuthFlowType.ADMIN_NO_SRP_AUTH }; request.AuthParameters.Add("USERNAME", user.Username); request.AuthParameters.Add("PASSWORD", user.Password); try { var response = await cognito.AdminInitiateAuthAsync(request); return(ResponseMessageHelper.Ok(response.AuthenticationResult.IdToken)); } catch (NotAuthorizedException ex) { return(ResponseMessageHelper.Unauthorized(ex.Message)); } catch (Exception ex) { return(ResponseMessageHelper.InternalServerError(ex.Message)); } }
public IActionResult Reset() { try { _battleshipGameService.ResetGame(); return(ResponseMessageHelper.Ok("")); } catch (BattleshipGameException ex) { return(ResponseMessageHelper.BadRequest(ex.Message)); } catch (Exception ex) { //write exception to a error log return(ResponseMessageHelper.InternalServerError()); } }
public IActionResult CreateBoard() { try { string username = GetCurrentUserName(); _battleshipGameService.CreateBoard(username, _config.Value.BoardSize); return(ResponseMessageHelper.OkCreated("Board created")); } catch (BattleshipGameException ex) { return(ResponseMessageHelper.BadRequest(ex.Message)); } catch (Exception ex) { //write exception to a error log return(ResponseMessageHelper.InternalServerError()); } }
public IActionResult CreatePlayer() { try { var playerName = GetCurrentUserName(); _battleshipGameService.CreatePlayer(playerName); return(ResponseMessageHelper.OkCreated($"Good Luck! {playerName}")); } catch (BattleshipGameException ex) { return(ResponseMessageHelper.BadRequest(ex.Message)); } catch (Exception ex) { //write exception to a error log return(ResponseMessageHelper.InternalServerError()); } }
public IActionResult Attack(AttackModel attackModel) { try { string username = GetCurrentUserName(); var result = _battleshipGameService .Attack(username, attackModel.Position); return(ResponseMessageHelper.Ok(result.ToString())); } catch (BattleshipGameException ex) { return(ResponseMessageHelper.BadRequest(ex.Message)); } catch (Exception ex) { //write exception to a error log return(ResponseMessageHelper.InternalServerError()); } }