Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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);
        }