// GET api/Employee/5 public Empdemo GetEmpdemo(int id) { Empdemo empdemo = db.Empdemoes.Find(id); if (empdemo == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return(empdemo); }
// POST api/Employee public HttpResponseMessage PostEmpdemo(Empdemo empdemo) { if (ModelState.IsValid) { db.Empdemoes.Add(empdemo); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, empdemo); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = empdemo.code })); return(response); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
// DELETE api/Employee/5 public HttpResponseMessage DeleteEmpdemo(int id) { Empdemo empdemo = db.Empdemoes.Find(id); if (empdemo == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } db.Empdemoes.Remove(empdemo); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK, empdemo)); }
// PUT api/Employee/5 public HttpResponseMessage PutEmpdemo(int id, Empdemo empdemo) { if (ModelState.IsValid && id == empdemo.code) { db.Entry(empdemo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }