Exemplo n.º 1
0
        public async Task <IActionResult> Create2(HotelViewModel hotel)
        {
            if (ModelState.IsValid)
            {
                var entityHotel = new Hotel
                {
                    Name        = hotel.Name,
                    Description = hotel.Description
                };
                entityHotel.HotelAddress.Add(new HotelAddress
                {
                    HotelId     = hotel.Id,
                    AddressText = hotel.AddressText,
                    PostalCode  = hotel.PostalCode,
                    CityId      = hotel.CityId
                });
                entityHotel.HotelRoom.Add(new HotelRoom
                {
                    HotelId     = hotel.Id,
                    RoomTypeId  = hotel.RoomTypeId,
                    RoomDetail  = hotel.RoomDetail,
                    RoomSummary = hotel.RoomSummary,
                });
                entityHotel.HotelImage.Add(new HotelImage
                {
                    HotelId     = hotel.Id,
                    ImagePath   = hotel.ImagePath,
                    Description = hotel.Description
                });
                entityHotel.HotelContact.Add(new HotelContact
                {
                    HotelId            = hotel.Id,
                    HotelContactTypeId = hotel.HotelContactTypeId,
                    ContactValue       = hotel.ContactValue
                });
                //_context.HotelContact.Add(new HotelContact
                //{
                //    HotelId = hotel.Id,
                //    HotelContactTypeId = hotel.HotelContactTypeId,
                //    ContactValue = hotel.ContactValue,
                //});
                entityHotel.HotelScore.Add(
                    new HotelScore
                {
                    HotelId          = hotel.Id,
                    HotelScoreTypeId = hotel.HotelScoreTypeId,
                    ScoreValue       = hotel.ScoreValue
                }
                    );
                _context.Hotel.Add(entityHotel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hotel));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Hotel> > PostHotel(Hotel hotel) // The hotel fields are given as JSON in the body fo the post, and implicitly converted to a Hotel object.
        {
            HotelDB.Hotels.Add(hotel);                                   // Add Hotel object to the database context that accesses Hotels tables of database
            await HotelDB.SaveChangesAsync();                            // Update database

            // Return a CreatedAtActionResult (201) response, that indicates a new record has been made serverside, to the client.
            // The response will also build the url reference to this new object and put this in te location field of the header:
            // GetHotels function -> Get request to root of this API /api/BookingAPI/Hotel/id
            // + The id of the new record to access it = /api/BookingAPI/Hotel/id/{id}
            return(CreatedAtAction(nameof(GetHotel), new { id = hotel.Id }, hotel));
        }
Exemplo n.º 3
0
        public async Task <bool> Add(Room model)
        {
            try
            {
                await _context.Rooms.AddAsync(model);

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 4
0
        public async Task <bool> CustomerInformationThatBookRoom(Customer customer)
        {
            try
            {
                await _hotelDBContext.Customers.AddAsync(customer);

                await _hotelDBContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> PutHotel(int id, Hotel dHotel)
        {
            dHotel.Id = id;

            _context.Entry(dHotel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HotelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 6
0
 public async Task Save()
 {
     await dbContext.SaveChangesAsync();
 }