public async Task <MotelRoom> BookRoomAsync(int roomNum, int numPets, bool needsAccessibility) { MotelRoom room = await FindRoomByNumber(roomNum); //if we get null here, the room is not available in the repository if (room == null) { throw new RoomBookingException($"Room {roomNum} is not available for booking"); } if (needsAccessibility && !room.IsHandicapAccessible()) { throw new RoomBookingException($"Room {roomNum} is not handicap accessible"); } if (numPets > 0) { if (room.AllowsPets()) { room.AddPets(numPets); } else { throw new RoomBookingException($"Room {roomNum} does now allow pets"); } } _repo.AddBookedRoom(room); room.TotalCost = CalculateCost(room); return(room); }
/// <summary> /// Searches and books for any available room that fit the criteria specified /// </summary> /// <param name="numBeds"></param> /// <param name="numPets"></param> /// <param name="needsAccessibility"></param> /// <returns></returns> public async Task <MotelRoom> BookAvailableRoomAsync(int numBeds, int numPets, bool needsAccessibility) { MotelRoom room = await FindRoomByProperties(numBeds, numPets, needsAccessibility); //if we get null here, the room is not available in the repository if (room == null) { throw new RoomBookingException($"Could not find available room that met the booking criteria"); } if (numPets > 0) { if (room.AllowsPets()) { room.AddPets(numPets); } else { throw new RoomBookingException($"Room {room.RoomNum} does now allow pets"); } } _repo.AddBookedRoom(room); room.TotalCost = CalculateCost(room); return(room); }
/// <summary> /// Searches, then books a room based on requested beds, pet policy, and accessibility /// </summary> /// <param name="numBeds"></param> /// <param name="numPets"></param> /// <param name="needsAccessibility"></param> /// <returns>Task that represents the async call </returns> public async Task <MotelRoom> BookAvailableRoomAsync(int numBeds, int numPets, bool needsAccessibility) { MotelRoom room = await FindRoomByProperties(numBeds, numPets, needsAccessibility); if (room == null) { throw new Exception($"No available room that matched booking criteria"); } if (numPets > 0) { if (room.AllowsPets()) { room.AddPets(numPets); } else { throw new Exception($"Room {room.RoomNum} does now allow pets"); } } _repo.AddBookedRoom(room); room.TotalCost = CalculateCost(room); return(room); }