コード例 #1
0
 public HttpResponseMessage Post(FoodBook c1)
 {
     try
     {
         db.FoodBooks.Add(c1);
         db.SaveChanges();
         return(new HttpResponseMessage(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
     }
 }
コード例 #2
0
 public HttpResponseMessage Put(int id, FoodBook c1)
 {
     try
     {
         if (id == c1.FBookid)
         {
             db.Entry(c1).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             return(new HttpResponseMessage(HttpStatusCode.OK));
         }
         else
         {
             return(new HttpResponseMessage(HttpStatusCode.NotFound));
         }
     }
     catch (Exception ex)
     {
         return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
     }
 }
コード例 #3
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         FoodBook c1 = db.FoodBooks.Find(id);
         if (c1 != null)
         {
             db.FoodBooks.Remove(c1);
             db.SaveChanges();
             return(new HttpResponseMessage(HttpStatusCode.OK));
         }
         else
         {
             return(new HttpResponseMessage(HttpStatusCode.NotFound));
         }
     }
     catch (Exception ex)
     {
         return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
     }
 }