// PUT api/Games/5 public HttpResponseMessage PutGame(int id, Game game) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != game.GameId) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(game).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
public ActionResult Create(Game game) { if (ModelState.IsValid) { db.Games.Add(game); db.SaveChanges(); return RedirectToAction("Index"); } return View(game); }
// POST api/Games public HttpResponseMessage PostGame(Game game) { if (ModelState.IsValid && game != null) { db.Games.Add(game); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, game); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = game.GameId })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public ActionResult Edit(Game game) { if (ModelState.IsValid) { db.Entry(game).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(game); }