public void Put(int id, [FromBody] Players player) { using (projDBEntities entities = new projDBEntities()) { var entity = entities.Players.FirstOrDefault(e => e.player_Id == id); Update(entity, player); } }
public List <Players> Get() { using (projDBEntities entities = new projDBEntities()) { List <Players> ret = new List <Players>(); foreach (Players p in entities.Players) { ret.Add(ClonePlayers(p)); } return(ret); } }
public HttpResponseMessage Get(int Id) { using (projDBEntities entities = new projDBEntities()) { Players obj = entities.Players.FirstOrDefault(e => e.player_Id == Id); if (obj != null) { return(Request.CreateResponse(HttpStatusCode.OK, ClonePlayers(obj))); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, String.Format(NOT_FOUND_MSG, obj))); } //return new Players(obj); } }
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)); } }