//Add Leavetype public HttpResponseMessage Post([FromBody] LEAVETYPE leavetype) { try { using (LeaveTypeEntities entity = new LeaveTypeEntities()) { entity.LEAVETYPE.Add(leavetype); entity.SaveChanges(); HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.Created, leavetype); message.Headers.Location = new Uri(Request.RequestUri + leavetype.LeaveTypeId.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
//Delete Leavetype public HttpResponseMessage Delete(int id) { try { using (LeaveTypeEntities entity = new LeaveTypeEntities()) { var record = entity.LEAVETYPE.FirstOrDefault(e => e.LeaveTypeId == id); if (record == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "record doesnt exist")); } else { entity.LEAVETYPE.Remove(record); entity.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
//Update Leavetype public HttpResponseMessage Put(int id, [FromBody] LEAVETYPE leavetype) { try { using (LeaveTypeEntities entity = new LeaveTypeEntities()) { var en = entity.LEAVETYPE.Find(id); if (en == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "record doesn't exist")); } else { en.LeaveTypeName = leavetype.LeaveTypeName; entity.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }