Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public void ReserveRoom(List<reservationtype> reservation)
       {
           List<reservationtype> RequestReservation = new List<reservationtype>();

           RequestReservation = reservation;   //List that contains the test cases.

           string reservationid = "0001";
           int number = int.Parse(reservationid);

           int count = 0;

           foreach (ReservationType requestReservation in RequestReservation)
           {
               List<string> DateList = CreateDateList(requestReservation.StartDate, requestReservation.numDays);

               foreach (Inventory inventory in RoomInventory)
               {
                  if (requestReservation.hotelId.Equals (inventory.HotelId))
                   {

                     if (requestReservation.roomType == inventory.RoomType)
                       {

                              for (int i = 0; i < DateList.Count; i++)
                              {
                       if (DateList[i].Equals(inventory.Date) && inventory.Quantity > 0)
                               {

                                   count++;

                                   if (requestReservation.numDays == count)
                                   {
                                       for (int j = 0; j < DateList.Count; j++)
                                       {
                                          if (DateList[j].Equals(inventory.Date))
                                               {
                                                 inventory.Quantity--;

                                               }

                                       }

                                       requestReservation.reservationId = "000" + (number + 1).ToString();
                                       requestReservation.result = ReservationType.ReservationResultType.Success;
                                       count = 0;

                                       foreach (Hotels h in LHotels)
                                       {
                                           foreach (Room rm in h.RoomList)
                                           {
                                               if (requestReservation.hotelId == h.HotelId && requestReservation.roomType == rm.RoomType)
                                               {
                                                   requestReservation.cost = (requestReservation.numDays * rm.Rate);
                                               }

                                           }
                                       }
                                   } // end of if num == counts
                                   else {
                                       requestReservation.reservationId = null;
                                       requestReservation.result = ReservationType.ReservationResultType.RoomNotAvailable;
                                       count = 0;
                                   }

                               } //end of if


                           }//end of forloop

                       }//end of if statement (Roomtypes)

                   }//end of If statement( inventory.hotelID)

               } // end of foreach inventory
               number++;
           }// end of Foreach

           serial = new XmlSerializer(RequestReservation.GetType());
           sw = new StreamWriter(ReservationFilename);
           serial.Serialize(sw, RequestReservation);
           sw.Close();


       }// End of ReserveRoom Method


What I have tried:

1)after the condition was true, i did forloop to go through each variables where datelist[i] == inventory.date and deduct 1 from it.

2) without the for loop, after condition was true, deduct 1 , but did not change at all.
Posted
Updated 5-Nov-16 18:56pm
Comments
Philippe Mori 30-Oct-16 19:01pm    
How Quantity and Inventory are defined...

I wrote a function recently that starts incrementing a value then when the peak is reached it starts decrementing, i used it to animate rgb colors on page


C#
var current;
const min = 0;
const max = 255;
var b = true;

    if (b == true) {
        current += 1;
        if (current >= max) {
            b = false;
        }
    }
    else {
        current = current - 1;
        if (current <= min) {
            b = true;
    }
 
Share this answer
 
There is no real question here, but I guess your code don't work as expected.
Without your data, we can't devise what is going on.
The only possibility is to use the debugger and check the variables values as the code is executing.

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900