public static Game ToGame(this GameDto gameDto) { if (!MongoIdValidator.Check(gameDto.id)) { gameDto.id = ObjectId.Empty.ToString(); } return(new Game { Id = new ObjectId(gameDto.id), Title = gameDto.title, Genre = gameDto.genre }); }
public HttpResponseMessage<GameDto> Put(string id, GameDto game) { if (!CheckIdAndExists(id)) throw new HttpResponseException(HttpStatusCode.NotFound); var updated = _gamesService.Update(id, game.ToGame()); return new HttpResponseMessage<GameDto>(updated.ToDto(), HttpStatusCode.OK); }
public HttpResponseMessage<GameDto> Post(GameDto game) { var created = _gamesService.Create(game.ToGame()); if (created == null) throw new HttpResponseException(HttpStatusCode.BadRequest); return new HttpResponseMessage<GameDto>(created.ToDto(), HttpStatusCode.Created); }