public static Game ConvertDtoToModel(GameUploadDto dto) { return(new Game() { Name = dto.Name, DeveloperId = dto.DeveloperId, Price = dto.Price, Description = dto.Description, ReleaseDate = DateTime.Now, Genre = ConvertGenderFieldToEnum(dto.Gender) }); }
public async Task <IActionResult> PostGame([FromBody] GameUploadDto gameDto) { if (gameDto == null) { return(BadRequest()); } try { var game = GameMapper.ConvertDtoToModel(gameDto); _context.Game.Add(game); await _context.SaveChangesAsync(); SaveGameTrailer(game.Id, gameDto.TrailerUrl); return(Ok(game.Id)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }