Пример #1
0
        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));
        }
Пример #2
0
        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));
        }
Пример #3
0
        public async Task <IHttpActionResult> GetHotel(string id)
        {
            Entity.Hotel hotel = await db.Hotel.FindAsync(id);

            if (hotel == null)
            {
                return(NotFound());
            }

            return(Ok(hotel));
        }
Пример #4
0
        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));
        }
Пример #5
0
        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));
        }