public HttpResponseMessage Putleavestatus(int leaveid, [FromBody] LEAVES leave) { try { using (LeaveEntities entity = new LeaveEntities()) { var en = entity.LEAVES.FirstOrDefault(e => e.LeaveId == leaveid); if (en == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "leave record doesn't exist")); } else { en.LeaveStatus = leave.LeaveStatus; entity.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
// Add leave data public HttpResponseMessage Post([FromBody] LEAVES leave) { try { using (LeaveEntities entity = new LeaveEntities()) { entity.LEAVES.Add(leave); entity.SaveChanges(); HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.Created, leave); message.Headers.Location = new Uri(Request.RequestUri + leave.LeaveId.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
//get data for specific leave public HttpResponseMessage GetLeaveData(int id) { try { using (LeaveEntities entity = new LeaveEntities()) { LEAVES leave = entity.LEAVES.FirstOrDefault(e => e.LeaveId == id); if (leave != null) { return(Request.CreateResponse(HttpStatusCode.OK, leave)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No entity found with leave id :" + id)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }