// POST api/EmployeeType public HttpResponseMessage PostEmployeeType(EmployeeType employeetype) { if (ModelState.IsValid) { employeetype.InsertBy = loginUser.UserID; db.EmployeeTypes.Add(employeetype); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, employeetype); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = employeetype.EmployeeTypeID })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/EmployeeType/5 public HttpResponseMessage PutEmployeeType(long id, EmployeeType employeetype) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != employeetype.EmployeeTypeID) { return Request.CreateResponse(HttpStatusCode.BadRequest); } employeetype.UpdateBy = loginUser.UserID; db.Entry(employeetype).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }