title: Hotel booking / Reservation logic
body: <p>I am working working on a very simple hotel booking project using Visual Studio 2013 Community for my coding class where the user can book a customer into a room and the program should stop the user if the room is already booked on that date or they overlap in some way with other bookings. </p>
  
  <p>The problem I am facing is that if the user makes a new booking where the Check In and Check Out dates are the same as 2 other bookings Check Out dates, it can overlap over another booking.</p>
  
  <p>Example:<br>
  Booking A - 01.01.15 to 02.01.15<br>
  Booking B - 03.01.15 to 04.01.15<br>
  Booking C - 05.01.15 to 06.01.15<br>
  Booking D - 02.01.15 to 06.01.15</p>
  
  <p>In booking D the user puts 02.01.15 as the Check In and 06.01.15 as Check Out and for some reason the program does not catch it and allows the booking over B and C.</p>
  
  <pre><code>public override void Add(Booking booking)
      {
          // Don't allow a new booking if the room is already out.
  
          var currentBooking = _ctx.Bookings
              .Where(b =&gt; b.RoomId == booking.RoomId)               
              .Select(b =&gt; (booking.CheckOut &gt; b.CheckIn &amp;&amp; booking.CheckIn &lt; b.CheckOut)
                        || (booking.CheckIn &lt; b.CheckIn &amp;&amp; booking.CheckOut &gt; b.CheckIn)) 
  
              .FirstOrDefault();
  
          if (currentBooking)
          {
                throw new BookingException("The Room is already out on that date.");
          }
  
          _ctx.Set&lt;Booking&gt;().Add(booking);
          _ctx.SaveChanges();
      }
  </code></pre>
  
  <p>I would have thought that by checking if the new Check In and Check Out were both the same as previous Check Out (see below) I would solve the problem but there must be something wrong with that logic. </p>
  
  <pre><code>.Select(b =&gt; (booking.CheckOut &gt; b.CheckIn &amp;&amp; booking.CheckIn &lt; b.CheckOut)
            || (booking.CheckIn &lt; b.CheckIn &amp;&amp; booking.CheckOut &gt; b.CheckIn)
            || (booking.CheckIn == b.CheckOut &amp;&amp; booking.CheckOut == b.CheckOut)) 
  </code></pre>
  
  <p>Should I be doing something like checking if the new Check In and Check Out are the same as previous Check Out´s -1 day?</p>