Ejemplo n.º 1
0
 public IActionResult SubmitScore([FromBody] Score score)
 {
     try
     {
         // The score should be submit by levelม it should unique by player and level
         if (_scoreRepository.IsScoreAlreadySubmitted(score.Player, score.Level))
         {
             var newScore = new ScoreEntity()
             {
                 Player = score.Player,
                 Level  = score.Level,
                 Time   = score.Time,
                 Step   = score.Step
             };
             var currentScore = _scoreRepository.GetScore(score.Player);
             if (newScore.Score > currentScore.Score)
             {
                 _scoreRepository.UpdateScore(score.Player, score.Level, score.Time, score.Step);
             }
         }
         else
         {
             _scoreRepository.AddNewScore(score.Player, score.Level, score.Time, score.Step);
         }
         return(Ok(score));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }