コード例 #1
0
 public void addRoom(int numSingleBeds, int numDoubleBeds, int maxGuests, int singlePrice, int doublePrice, int extraPrice, int roomNumber, String extraFeatures)
 {
     using (var context = new HotelDBEntities()) {
         Room newRoom = new Room { numSingleBeds = numSingleBeds, numDoubleBeds = numDoubleBeds, maxGuests = maxGuests, singePrice = singlePrice, doublePrice = doublePrice, extraPrice = extraPrice, roomNumber = roomNumber, extraFeatures = extraFeatures};
         context.Rooms.Add(newRoom);
         context.SaveChanges();
     }
 }
コード例 #2
0
 /*calculate room cost
  * guest is charged for all beds currently in the room.
  * if the number of guests exceeds the current beds, (2 guests to a doublebed)
  * the guest is charged the "extraPrice" of the room for every extra guest
  */
 public int calcRoomCost(Room room, int numGuests)
 {
     int price = 0;
     price = (room.singePrice * room.numSingleBeds) + (room.numDoubleBeds * room.doublePrice);
     int remainingGuests = (numGuests - room.numSingleBeds) - (room.numDoubleBeds * 2);
     if (remainingGuests > 0)
         price += remainingGuests * (int)room.extraPrice;
     return price;
 }
コード例 #3
0
 public Room[] getRooms(Room[] avRooms, int numGuests, int numSingleBeds, int numDoubleBeds, int maxPrice)
 {
     var filteredRooms = avRooms.Where(r => r.maxGuests >= numGuests);
     if (numSingleBeds > 0)//filter singleBeds
         filteredRooms = filteredRooms.Where(r => r.numSingleBeds >= numSingleBeds);
     if (numDoubleBeds > 0)//filter doubleBeds
         filteredRooms = filteredRooms.Where(r => r.numDoubleBeds >= numDoubleBeds);
     if (maxPrice > 0)
         filteredRooms = filteredRooms.Where(r => calcRoomCost(r, numGuests) <= maxPrice);
     return filteredRooms.ToArray();//from room IEnumerable to room[]
 }