コード例 #1
0
ファイル: GamesController.cs プロジェクト: camotts/383-Api
        public HttpResponseMessage PostGame(Game game)
        {
            if (ModelState.IsValid)
            {

                repo.createGame(game);
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, game);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = game.ID }));

                GameDTO factoredGame = TheFactory.Create(game);

                return Request.CreateResponse(HttpStatusCode.OK, factoredGame);

            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
コード例 #2
0
ファイル: GamesController.cs プロジェクト: camotts/383-Api
        public HttpResponseMessage PutGame(int id, Game game)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != game.ID)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            repo.putGame(id, game);
            //try
            //{
            //    db.SaveChanges();
            //}
            //catch (DbUpdateConcurrencyException ex)
            //{
            //    return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            //}
            GameDTO factoredGame = TheFactory.Create(game);

            return Request.CreateResponse(HttpStatusCode.OK, factoredGame);
        }