Пример #1
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         using (RestaurantWebAPI20180109074303_dbEntities entities = new RestaurantWebAPI20180109074303_dbEntities())
         {
             var entity = entities.Restaurants.FirstOrDefault(e => e.restaurantId == id);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound,
                                                    "Restaurant with Id = " + id.ToString() + " not found to delete"));
             }
             else
             {
                 entities.Restaurants.Remove(entity);
                 entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Пример #2
0
 public HttpResponseMessage Get()
 {
     using (RestaurantWebAPI20180109074303_dbEntities entities = new RestaurantWebAPI20180109074303_dbEntities()) {
         var rest = entities.Restaurants.ToList();
         return(Request.CreateResponse(HttpStatusCode.OK, rest));
     }
 }
Пример #3
0
 public HttpResponseMessage GetCuisinesAndCity(string restaurantCuisineType, string restaurantCity)
 {
     using (RestaurantWebAPI20180109074303_dbEntities entities = new RestaurantWebAPI20180109074303_dbEntities())
     {
         var restaurant = entities.Restaurants.Where(e => e.restaurantCuisineType == restaurantCuisineType && e.restaurantCity == restaurantCity).ToList();
         return(Request.CreateResponse(HttpStatusCode.OK, restaurant));
     }
 }
Пример #4
0
 public HttpResponseMessage GetClosingTime(string restaurantCloseTime)
 {
     using (RestaurantWebAPI20180109074303_dbEntities entities = new RestaurantWebAPI20180109074303_dbEntities())
     {
         var restaurant = entities.Restaurants.Where(e => e.restaurantClosingTime == restaurantCloseTime).ToList();
         return(Request.CreateResponse(HttpStatusCode.OK, restaurant));
     }
 }
Пример #5
0
 public HttpResponseMessage Get(int id)
 {
     using (RestaurantWebAPI20180109074303_dbEntities entities = new RestaurantWebAPI20180109074303_dbEntities())
     {
         var restaurant = entities.Restaurants.FirstOrDefault(e => e.restaurantId == id);
         return(Request.CreateResponse(HttpStatusCode.OK, restaurant));
     }
 }
Пример #6
0
 public HttpResponseMessage Post([FromBody] Restaurant restaurant)
 {
     try
     {
         using (RestaurantWebAPI20180109074303_dbEntities entities = new RestaurantWebAPI20180109074303_dbEntities())
         {
             var message = Request.CreateResponse(HttpStatusCode.Created, restaurant);
             message.Headers.Location = new Uri(Request.RequestUri +
                                                restaurant.restaurantId.ToString());
             return(message);
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }