示例#1
0
 public HttpResponseMessage SaveRestaurant(Restaurant restaurant)
 {
     try
     {
         using (var db = new DM.RestaurantReviewEntities())
         {
             var restaurantDb = restaurant.Save(db);
             db.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK, restaurantDb?.Id ?? 0));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
 public HttpResponseMessage DeleteReview(int id)
 {
     try
     {
         using (var db = new DM.RestaurantReviewEntities())
         {
             var review = db.Reviews.SingleOrDefault(rv => rv.Id == id);
             if (review == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Review Not Found"));
             }
             db.Reviews.Remove(review);
             db.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK, true));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }