public IHttpActionResult GetGameById(int Id) { if (HaloGames.Exists(x => x.Id == Id)) { HaloGame game = HaloGames.Find(x => x.Id == Id); if (Id == 5) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new ObjectContent <HaloGame>(game, new JsonMediaTypeFormatter()); response.Headers.CacheControl = new CacheControlHeaderValue() { MaxAge = TimeSpan.FromMinutes(2) }; return(ResponseMessage(response)); } else { return(Ok(game)); } } else { return(NotFound()); } }
public IHttpActionResult PostNewGame([FromBody] HaloGame game) { try { HaloGames.Add(game); } catch (Exception e) { return(StatusCode(HttpStatusCode.InternalServerError)); } return(CreatedAtRoute("MyAwesomeApi", new { id = game.Id }, game)); }
public IHttpActionResult GetGameById(int Id) { if (HaloGames.Exists(x => x.Id == Id)) { HaloGame game = HaloGames.Find(x => x.Id == Id); return(Ok(game)); } else { return(NotFound()); } }
public IHttpActionResult DeleteGame(int Id) { if (HaloGames.Exists(x => x.Id == Id)) { HaloGame game = HaloGames.Find(x => x.Id == Id); HaloGames.Remove(game); return(Ok(game)); } else { return(NotFound()); } }
// GET: HaloGames/Details/5 public ActionResult Details(int id) { HaloGame game = HaloGames.Find(x => x.Id == id); if (game != null) { return(View(game)); } else { return(new HttpNotFoundResult()); } }
public ActionResult Create(HaloGame game) { try { if (ModelState.IsValid) { game.Id = HaloGames.Count + 1; HaloGames.Add(game); return(RedirectToAction("Index")); } else { return(View()); } } catch { return(View()); } }
public ActionResult Edit(int id, HaloGame game) { try { if (ModelState.IsValid) { HaloGame gameToEdit = HaloGames.Find(x => x.Id == id); gameToEdit.Title = game.Title; gameToEdit.ReleaseDate = game.ReleaseDate; } else { return(View()); } return(RedirectToAction("Index")); } catch { return(View()); } }
public IHttpActionResult PutGameUpdate(int Id, [FromBody] HaloGame game) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (Id != game.Id) { return(BadRequest()); } if (HaloGames.Exists(x => x.Id == game.Id)) { HaloGame gameToUpdate = HaloGames.Find(x => x.Id == game.Id); gameToUpdate.Title = game.Title; gameToUpdate.ReleaseDate = game.ReleaseDate; return(StatusCode(HttpStatusCode.NoContent)); } else { return(NotFound()); } }
// GET: HaloGames/Edit/5 public ActionResult Edit(int id) { HaloGame game = HaloGames.Find(x => x.Id == id); return(View(game)); }