Пример #1
0
        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"));
        }
Пример #2
0
        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);
            }
        }