Пример #1
0
 public HttpResponseMessage Post([FromBody] NewHotelModel m)
 {
     using (HotelsContext c = new HotelsContext())
     {
         c.Hotel.Add(new Hotel()
         {
             Name = m.Name, City = m.City, Address = m.Address, Rating = m.Rating
         });
         c.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK));
     }
 }
Пример #2
0
 public HttpResponseMessage Put(int id, [FromBody] NewHotelModel m)
 {
     using (HotelsContext c = new HotelsContext())
     {
         Hotel h = (from hotel in c.Hotel where hotel.Id == id select hotel).FirstOrDefault();
         if (h == null)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound));
         }
         h.Name = m.Name; h.City = m.City; h.Address = m.Address; h.Rating = m.Rating;
         c.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK));
     }
 }