public HttpResponseMessage Post([FromBody] Players value) { try { using (projDBEntities entities = new projDBEntities()) { entities.Players.Add(value); entities.SaveChanges(); var msg = Request.CreateResponse(HttpStatusCode.Created, value); msg.Headers.Location = new Uri(Request.RequestUri + (Request.RequestUri.ToString().EndsWith("/") ? "" : "/") + value.player_Id.ToString()); return(msg); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Delete(int id) { try { using (projDBEntities entities = new projDBEntities()) { var entity = entities.Players.FirstOrDefault(e => e.player_Id == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, String.Format(NOT_FOUND_MSG, id))); } else { entities.Players.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }