public async Task <IActionResult> CreateScore(int gameId, NewScoreModel model) { var score = await _scoreService.CreateScoreAsync(gameId, model); return(score != null ? (IActionResult)CreatedAtAction(nameof(GetScore), new { gameId = score.GameId, id = score.Id }, score) : BadRequest("Failed to generate score")); }
public async Task <Score> CreateScoreAsync(int gameId, NewScoreModel model) { try { var dbItem = _mapper.Map <Score>(model); dbItem.GameId = gameId; await _context.Scores.AddAsync(dbItem); await _context.SaveChangesAsync(); return(dbItem); } catch (Exception ex) { Console.WriteLine(ex); return(null); } }