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