public async Task <IHttpActionResult> PostHotel(Entity.Hotel hotel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Hotel.Add(hotel); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (HotelExists(hotel.HotelId)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = hotel.HotelId }, hotel)); }
public async Task <IHttpActionResult> PutHotel(string id, Entity.Hotel hotel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != hotel.HotelId) { return(BadRequest()); } db.Entry(hotel).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HotelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetHotel(string id) { Entity.Hotel hotel = await db.Hotel.FindAsync(id); if (hotel == null) { return(NotFound()); } return(Ok(hotel)); }
public async Task <IHttpActionResult> DeleteHotel(string id) { Entity.Hotel hotel = await db.Hotel.FindAsync(id); if (hotel == null) { return(NotFound()); } db.Hotel.Remove(hotel); await db.SaveChangesAsync(); return(Ok(hotel)); }
public async Task <IHttpActionResult> GetSearchHotel(string hotelId, string date, int days, string supplierName) { Entity.Hotel hotel = await db.Hotel.FindAsync(hotelId); if (hotel == null) { return(NotFound()); } if (string.IsNullOrEmpty(supplierName)) { return(NotFound()); } var service = new SupplierFactory(supplierName).GetService(); var result = await service.GetHotelPrice(hotelId, date, days); return(Ok(result)); }