public IHttpActionResult PutHighScore(string userName) { var existingPlayer = _playersDataAccess.GetPlayer(userName); HighScore highScore; if (existingPlayer == null) { _playersDataAccess.InsertPlayer(new Player { UserName = userName }); highScore = new HighScore() { PlayerUserName = userName, Score = 1 }; _highScoreDataAccess.InsertHighScore(highScore); } else { highScore = _highScoreDataAccess.GetHighScore(existingPlayer.UserName); if (highScore == null) { highScore = new HighScore() { PlayerUserName = userName, Score = 1 }; _highScoreDataAccess.InsertHighScore(highScore); } else { highScore.Score++; _highScoreDataAccess.UpdateHighScore(highScore); } } return(Created(new Uri(Request.RequestUri + userName), highScore)); }
// PUT: api/players/Cameron public IHttpActionResult PutPlayer([FromUri] string userName) { try { var existingPlayer = _dataAccess.GetPlayer(userName); if (existingPlayer == null) { _dataAccess.InsertPlayer(new Player { UserName = userName }); } else { existingPlayer.UserName = userName; _dataAccess.UpdatePlayer(existingPlayer); } return(Created(new Uri(Request.RequestUri + userName), userName)); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }