Beispiel #1
0
        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));
            }
        }
Beispiel #2
0
 // 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));
     }
 }
Beispiel #3
0
 //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));
     }
 }