// PUT api/Games/5 public HttpResponseMessage Put(int id, [FromBody] GamesResolut value) { using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities()) { GamesResolut wanted = entities.GamesResoluts.FirstOrDefault(t => t.ID == id); if (wanted != null) { wanted.Game_Name = value.Game_Name; wanted.Player1 = value.Player1; wanted.Player2 = value.Player2; wanted.Who_Won_ = value.Who_Won_; //entities.SaveChanges(); try { //db.SaveChanges(); entities.SaveChanges(); } catch (DbEntityValidationException ex) { Console.WriteLine(ex); } return(Request.CreateResponse(HttpStatusCode.Accepted, wanted)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("The game with id: {0} not found", id))); } } }
// POST api/Games public HttpResponseMessage Post([FromBody] GamesResolut value) { using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities()) { entities.GamesResoluts.Add(value); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created, new Uri(Request.RequestUri + value.ID.ToString()))); } }
// GET api/Games/5 public HttpResponseMessage Get(int id) { using (WebAPI_FP_TournamentGamesEntities entities = new WebAPI_FP_TournamentGamesEntities()) { GamesResolut wanted = entities.GamesResoluts.FirstOrDefault(t => t.ID == id); if (wanted != null) { return(Request.CreateResponse(HttpStatusCode.OK, wanted)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format("The game with id: {0} not found", id))); } } }