Exemplo n.º 1
0
        public Task <bool> UpdateHotelRooms(long hotelId, CreateHotelRoom hotelRoomData)
        {
            throw new NotImplementedException();

            /* var hotelRoom = new HotelRoom
             * {
             *   RoomNumber = hotelRoomData.RoomNumber,
             *   Rate = hotelRoomData.Rate,
             *   RoomId = hotelRoomData.RoomId,
             * };
             *
             * _context.Entry(hotelRoom).State = EntityState.Modified;
             * try
             * {
             *   await _context.SaveChangesAsync();
             *   return true;
             * }
             * catch (DbUpdateConcurrencyException)
             * {
             *   if (!RoomExists(id))
             *   {
             *       return false;
             *   }
             *   else
             *   {
             *       throw;
             *   }
             * }*/
        }
Exemplo n.º 2
0
        public async Task <ActionResult <HotelRoom> > PostHotelRoom(CreateHotelRoom hotelRoomData)
        {
            var hotelRoom = await hotelRoomRepository.SaveNewHotelRoom(hotelRoomData);

            // params to get the routes <---remind for tomorrow
            return(CreatedAtAction("GetHotelRoom", new { hotelRoom.HotelId, hotelRoom.RoomNumber }, hotelRoom));
        }
Exemplo n.º 3
0
        public async Task AddRoomAsync(long hotelId, CreateHotelRoom hotelRoom)
        {
            var newHotelRoom = new HotelRoom
            {
                HotelId    = hotelId,
                RoomNumber = hotelRoom.RoomNumber
            };

            _context.HotelRooms.Add(newHotelRoom);
            await _context.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task <IActionResult> PutHotelRoom(int roomNumber, CreateHotelRoom hotelRoomData)
        {
            if (roomNumber != hotelRoomData.RoomNumber)
            {
                return(BadRequest());
            }

            bool updateComplete = await hotelRoomRepository.UpdateHotelRooms(roomNumber, hotelRoomData);

            if (!updateComplete)
            {
                return(NotFound());
            }

            return(NoContent());
        }
Exemplo n.º 5
0
        public async Task <HotelRoomDTO> CreateHotelRoom(long hotelId, CreateHotelRoom hotelRoomData)
        {
            var hotelRoom = new HotelRoom
            {
                HotelId    = hotelId,
                RoomNumber = hotelRoomData.RoomNumber,
                Rate       = hotelRoomData.Rate,
                RoomId     = hotelRoomData.RoomId,
            };

            _context.HotelRoom.Add(hotelRoom);
            await _context.SaveChangesAsync();

            // return CreatedAtAction("GetHotelRoom", new { id = hotelRoom.Id }, hotelRoom);
            var newHotelRoom = await GetHotelRoomByNumber(hotelRoom.RoomNumber, hotelRoomData.RoomId);

            return(newHotelRoom);
        }
Exemplo n.º 6
0
        public async Task <bool> UpdateHotelRooms(long hotelId, CreateHotelRoom hotelRoomData)
        {
            var hotelRoom = await _context.HotelRoom
                            .FirstOrDefaultAsync(hr => hr.HotelId == hotelId && hr.RoomNumber == hotelRoomData.RoomNumber);

            if (hotelRoom == null)
            {
                return(false);
            }

            hotelRoom.Rate   = hotelRoomData.Rate;
            hotelRoom.RoomId = hotelRoomData.RoomId;

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

            await _context.SaveChangesAsync();

            return(true);
        }
Exemplo n.º 7
0
        public async Task <HotelRoomDTO> CreateHotelRoom(CreateHotelRoom hotelRoomData)
        {
            var room = await _context.Room.FindAsync(hotelRoomData.RoomId);

            if (room == null)
            {
                return(null);
            }
            var hotelRoom = new HotelRoom
            {
                RoomNumber = hotelRoomData.RoomNumber,
                Rate       = hotelRoomData.Rate,
                RoomId     = hotelRoomData.RoomId,
            };

            _context.HotelRoom.Add(hotelRoom);
            await _context.SaveChangesAsync();

            // return CreatedAtAction("GetHotelRoom", new { id = hotelRoom.Id }, hotelRoom);
            var newHotelRoom = await GetHotelRoomById(hotelRoom.RoomNumber, hotelRoomData.RoomId);

            return(newHotelRoom);
        }
        public async Task Can_add_and_remove_room_to_hotel()
        {
            // Arrange
            var room = await CreateAndSaveTestRoom();

            var hotel = await CreateAndSaveTestHotel();

            var createRoom = new CreateHotelRoom()
            {
                RoomNumber = 14, Rate = 149.99m, PetFriendly = true, RoomId = room.Id
            };

            var repository = new DatabaseHotelRoomRepository(_db);

            // Act
            await repository.AddRoomAsync(
                hotelId : hotel.Id,
                hotelRoom : createRoom
                );

            // Assert
            var realHotelRoom = await repository.GetHotelRoomAsync(hotel.Id, createRoom.RoomNumber);

            Assert.Equal(14, realHotelRoom.RoomNumber);
            Assert.True(realHotelRoom.PetFriendly);

            // Act
            await repository.DeleteRoomAsync(
                hotelId : hotel.Id,
                roomNumber : createRoom.RoomNumber
                );

            // Assert
            realHotelRoom = await repository.GetHotelRoomAsync(hotel.Id, createRoom.RoomNumber);

            Assert.Null(realHotelRoom);
        }
Exemplo n.º 9
0
 public Task <HotelRoom> SaveNewHotelRoom(CreateHotelRoom hotelRoomData)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
        public async Task <ActionResult> AddRoom(long hotelId, CreateHotelRoom hotelRoom)
        {
            await repository.AddRoomAsync(hotelId, hotelRoom);

            return(CreatedAtAction(nameof(AddRoom), new { hotelId, hotelRoom.RoomNumber }, null));
        }