// POST api/Tornir public HttpResponseMessage Post([FromBody] Tornir value) { using (TornirDBEntities entity = new TornirDBEntities()) { entity.Tornirs.Add(value); entity.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created, new Uri(Request.RequestUri + value.ID.ToString()))); } }
// DELETE api/Tornir/5 public HttpResponseMessage Delete(int id) { using (TornirDBEntities entity = new TornirDBEntities()) { Tornir tornirToDeleate = entity.Tornirs.FirstOrDefault(x => x.ID == id); if (tornirToDeleate != null) { entity.Tornirs.Remove(tornirToDeleate); entity.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, string.Format($"tornir with id:{id} delated"))); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format($"tornir with id:{id} was not found"))); } } }
// PUT api/Tornir/5 public HttpResponseMessage Put(int id, [FromBody] Tornir value) { using (TornirDBEntities entity = new TornirDBEntities()) { Tornir tornirToUpdate = entity.Tornirs.FirstOrDefault(x => x.ID == id); if (tornirToUpdate != null) { tornirToUpdate.Game_Name = value.Game_Name; tornirToUpdate.Player1 = value.Player1; tornirToUpdate.Player2 = value.Player2; tornirToUpdate.Who_Won = value.Who_Won; entity.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, string.Format($"tornir with id: {id} updeted"))); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, string.Format($"tornir with id:{id} was not found"))); } } }