示例#1
0
        public async Task <ActionResult <AmenityDTO> > GetAmenity(int id)
        {
            var amenity = await _amenity.GetAmenity(id);

            if (amenity == null)
            {
                return(NotFound());
            }
            return(amenity);
        }
示例#2
0
        // GET: Amenities/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            var amenities = await _amenities.GetAmenity(id);

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

            return(View(amenities));
        }
示例#3
0
        public async Task <RoomDTO> GetRoom(int id, IAmenity amenity)
        {
            Room room = await _context.Rooms
                        .Where(x => x.Id == id)
                        .Include(x => x.RoomAmenities)
                        .FirstOrDefaultAsync();

            if (room == null)
            {
                return(null);
            }
            RoomDTO roomDTO = await _context.Rooms
                              .Where(x => x.Id == id)
                              .Select(x => new RoomDTO()
            {
                Id = x.Id, Name = x.Name, Layout = x.Layout
            })
                              .FirstOrDefaultAsync();

            List <AmenityDTO> amenityDTOs = new List <AmenityDTO>();

            foreach (RoomAmenities oneAmenity in room.RoomAmenities)
            {
                amenityDTOs.Add(await amenity.GetAmenity(oneAmenity.AmenityId));
            }
            roomDTO.Amenities = amenityDTOs;
            return(roomDTO);
        }
示例#4
0
        // GET: Amenities/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Amenity amenity = await _amenity.GetAmenity(id);

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

            return(View(amenity));
        }
示例#5
0
        public async Task <RoomDTO> GetRoom(int id)
        {
            //look in the db on the room table where the id is
            //equal to the id that was brought in as an argument
            var room = await _context.Rooms.Where(x => x.Id == id)
                       .Include(x => x.RoomAmenities)
                       .FirstOrDefaultAsync();

            RoomDTO dto = new RoomDTO
            {
                Name   = room.Name,
                Layout = room.Layout.ToString(),
                Id     = room.Id
            };

            dto.Amenities = new List <AmenityDTO>();
            foreach (var item in room.RoomAmenities)
            {
                dto.Amenities.Add(await _amenity.GetAmenity(item.AmenitiesId));
            }

            // Convert the whole Room a RoomDTO
            // some foreach loop
            // for every amentity thats in there call
            //  _amenities.GetAmentity(id)
            // which will return you a DTO
            return(dto);
        }
        /// <summary>
        /// A Specific Room associated with a Specific hotel that you want to query
        /// </summary>
        /// <param name="hotelId">The Hotel you are querying</param>
        /// <param name="roomNumber">The Room you are querying</param>
        /// <returns>No Return</returns>
        public async Task <HotelRoomDTO> GetHotelRoom(int hotelId, int roomNumber)
        {
            var result = await _context.HotelRooms
                         .Where(x => x.HotelID == hotelId && x.RoomNumber == roomNumber)
                         .Include(x => x.Room)
                         .ThenInclude(x => x.RoomAmenities)
                         .ThenInclude(x => x.Amenity)
                         .FirstOrDefaultAsync();

            List <AmenityDTO> amenityDTO = new List <AmenityDTO>();

            foreach (var amenity in result.Room.RoomAmenities)
            {
                amenityDTO.Add(await _amenity.GetAmenity(amenity.AmenitiesID));
            }

            RoomDTO roomDTO = new RoomDTO()
            {
                ID        = result.Room.Id,
                Name      = result.Room.Name,
                Layout    = result.Room.Layout,
                Amenities = amenityDTO
            };

            HotelRoomDTO hotelRoomDTO = new HotelRoomDTO()
            {
                HotelID     = result.HotelID,
                RoomNumber  = result.RoomNumber,
                PetFriendly = result.PetFriendly,
                Rate        = result.Rate,
                RoomID      = result.RoomId,
                Room        = roomDTO
            };


            return(hotelRoomDTO);
        }
示例#7
0
        /// <summary>
        /// Gets a specific room from the database
        /// </summary>
        /// <param name="id">Id for room to be retrieved</param>
        /// <returns>Successful result of specified roomDTO</returns>
        public async Task <RoomDTO> GetRoom(int id)
        {
            var room = await _context.Rooms.Where(x => x.Id == id)
                       .Include(x => x.Amenities)
                       .FirstOrDefaultAsync();

            RoomDTO newRoom = new RoomDTO
            {
                ID     = room.Id,
                Name   = room.Name,
                Layout = room.FloorPlan.ToString(),
            };

            newRoom.Amenities = new List <AmenityDTO>();
            foreach (var amenity in room.Amenities)
            {
                newRoom.Amenities.Add(await _amenities.GetAmenity(amenity.AmenityId));
            }
            return(newRoom);
        }
示例#8
0
        /// <summary>
        /// GetRoom - gets a room individually by ID
        /// </summary>
        /// <param name="id">the id of the room we want to get </param>
        /// <returns>the returned room</returns>
        public async Task <RoomDTO> GetRoom(int id)
        {
            // look in the db on the room table where the id is equal to the one brought in as an argument
            //Room room = await _context.Rooms.FindAsync(id);

            // include all the RoomAmenities that the room has
            //var roomAmenities = await _context.RoomAmenities.Where(x => x.RoomId == id)
            //                                                .Include(x => x.Amenity)
            //                                                .ToListAsync();

            // From class repo:

            var room = await _context.Rooms.Where(x => x.Id == id)
                       .Include(x => x.RoomAmenities)
                       .ThenInclude(x => x.Amenity)
                       .FirstOrDefaultAsync();

            if (room == null)
            {
                return(null);
            }
            else
            {
                RoomDTO dto = new RoomDTO
                {
                    Name   = room.Name,
                    Layout = room.Layout.ToString(),
                    Id     = room.Id
                };

                dto.Amenities = new List <AmenityDTO>();

                foreach (var item in room.RoomAmenities)
                {
                    dto.Amenities.Add(await _amenities.GetAmenity(item.AmenityId));
                }

                //room.RoomAmenities = roomAmenities;
                return(dto);
            }
        }
示例#9
0
        /// <summary>
        /// Returns a list of all of the RoomAmenities associated with the specified room,
        /// in the Rooms database table
        /// </summary>
        /// <param name="id">Unique identifier of the room</param>
        /// <returns>A list of all RoomAmenities in the specific room</returns>
        public async Task <RoomDTO> GetRoom(int id)
        {
            var room = await _context.Rooms.Where(r => r.Id == id)
                       .Include(r => r.RoomAmenities)
                       .ThenInclude(ra => ra.Amenity)
                       .FirstOrDefaultAsync();

            RoomDTO roomDto = new RoomDTO
            {
                ID     = room.Id,
                Name   = room.Name,
                Layout = room.Layout,
            };

            roomDto.Amenities = new List <AmenityDTO>();

            foreach (var amenity in room.RoomAmenities)
            {
                roomDto.Amenities.Add(await _amenity.GetAmenity(amenity.AmenityId));
            }

            return(roomDto);
        }
示例#10
0
        public async Task <List <RoomDTO> > GetRooms(IAmenity amenity)
        {
            List <Room> rooms = await _context.Rooms
                                .Include(x => x.RoomAmenities)
                                .ToListAsync();

            List <RoomDTO> roomDTOs = new List <RoomDTO>();

            foreach (Room oneRoom in rooms)
            {
                RoomDTO newRoomDTO = new RoomDTO()
                {
                    Id = oneRoom.Id, Name = oneRoom.Name, Layout = oneRoom.Layout
                };
                List <AmenityDTO> amenityDTOs = new List <AmenityDTO>();
                foreach (RoomAmenities oneAmenity in oneRoom.RoomAmenities)
                {
                    amenityDTOs.Add(await amenity.GetAmenity(oneAmenity.AmenityId));
                }
                newRoomDTO.Amenities = amenityDTOs;
                roomDTOs.Add(newRoomDTO);
            }
            return(roomDTOs);
        }
示例#11
0
        /// <summary>
        /// Gets a single room
        /// </summary>
        /// <param name="id"> room identifier</param>
        /// <returns> The room with all its amenities</returns>
        public async Task <RoomDTO> GetRoom(int id)
        {
            Room room = await _context.Rooms.FindAsync(id);

            // includes all of the amenities in that room.
            var roomAmenities = await _context.RoomAmenities.Where(x => x.RoomId == id)
                                .Include(x => x.amenity)
                                .ToListAsync();

            RoomDTO dto = new RoomDTO()
            {
                Id     = room.Id,
                Name   = room.Name,
                Layout = room.Layout.ToString()
            };

            dto.Amenities = new List <AmenityDTO>();
            foreach (var item in roomAmenities)
            {
                dto.Amenities.Add(await _amenity.GetAmenity(item.amenity.Id));
            }

            return(dto);
        }
示例#12
0
      public async Task <ActionResult <AmenityDTO> > GetAmenity(int id)
      {
          AmenityDTO amenity = await _amenity.GetAmenity(id);

          return(amenity);
      }
示例#13
0
 public async Task <ActionResult <AmenityDTO> > GetAmenity(int id)
 {
     return(await _amenity.GetAmenity(id));
 }