Exemple #1
0
        public async Task <DbEntity_Game> CreateAsync(CreateDto_Game newGame)
        {
            var createdGame = Mapper.Map <DbEntity_Game>(newGame);
            var success     = await CreateAsync(createdGame);

            return(createdGame);
        }
        public async Task <IActionResult> Create([FromBody] CreateDto_Game newGame)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(new ErrorResponse(ModelState)));
                }
                var createdGame = await _gameService.CreateAsync(newGame);

                await _gameService.AddCollaboratorAsync(createdGame, newGame.UserId);

                await _gameService.SaveChangesAsync();

                var dtoGame = Mapper.Map <Dto_Game>(createdGame);
                return(StatusCode(StatusCodes.Status201Created, dtoGame));
            }
            catch (NotFoundException ex)
            {
                return(NotFound(new ErrorResponse(ex)));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }