コード例 #1
0
 public HttpResponseMessage Put(int id, [FromBody] HOLIDAYS h)
 {
     try
     {
         using (HolidayEntities e = new HolidayEntities())
         {
             var entity = e.HOLIDAYS.Find(id);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No holiday exist"));
             }
             else
             {
                 entity.HolidayDate      = h.HolidayDate;
                 entity.HolidayName      = h.HolidayName;
                 entity.WorkDuration     = h.WorkDuration;
                 entity.RepeatedAnnually = h.RepeatedAnnually;
                 e.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
コード例 #2
0
 public HttpResponseMessage Post([FromBody] HOLIDAYS h)
 {
     try
     {
         using (HolidayEntities e = new HolidayEntities())
         {
             e.HOLIDAYS.Add(h);
             e.SaveChanges();
             HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.Created, h);
             message.Headers.Location = new Uri(Request.RequestUri + h.HolidayId.ToString());
             return(message);
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
コード例 #3
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         using (HolidayEntities entity = new HolidayEntities())
         {
             var record = entity.HOLIDAYS.FirstOrDefault(e => e.HolidayId == id);
             if (record == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "leave record doesnt exist"));
             }
             else
             {
                 entity.HOLIDAYS.Remove(record);
                 entity.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }