예제 #1
0
        public HttpResponseMessage Put(int Id, [FromBody] Leaf leaveRequest)
        {
            using (LeavesEntities leaveEntity = new LeavesEntities())
            {
                try
                {
                    var leave = leaveEntity.Leaves.FirstOrDefault(L => L.Id == Id);

                    if (leave == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Leave with Id " + Id + " not found."));
                    }

                    leave.EmployeeName  = leaveRequest.EmployeeName;
                    leave.EmployeeEmail = leaveRequest.EmployeeEmail;
                    leave.ManagerName   = leaveRequest.ManagerName;
                    leave.ManagerEmail  = leaveRequest.ManagerEmail;
                    leave.FromDate      = leaveRequest.FromDate;
                    leave.ToDate        = leaveRequest.ToDate;
                    leaveEntity.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.OK, "Leave Request Updated."));
                }
                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
                }
            }
        }
예제 #2
0
 public HttpResponseMessage Post([FromBody] Leaf leaveRequest)
 {
     using (LeavesEntities leaveEntity = new LeavesEntities())
     {
         leaveEntity.Leaves.Add(leaveRequest);
         leaveEntity.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.Created, "New Leave Request Created."));
         //return Ok("New Leave Request Created.");
     }
 }
예제 #3
0
        public HttpResponseMessage Delete(int Id)
        {
            using (LeavesEntities leaveEntity = new LeavesEntities())
            {
                var leave = leaveEntity.Leaves.FirstOrDefault(L => L.Id == Id);
                if (leave == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Leave with Id " + Id + " not found."));
                }

                leaveEntity.Leaves.Remove(leaveEntity.Leaves.FirstOrDefault(L => L.Id == Id));
                leaveEntity.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.OK, "Leave Request Deleted."));
            }
        }