예제 #1
0
 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
     });
 }
예제 #2
0
 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);
 }
예제 #3
0
 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);
 }