In my application I am using Entity Framework.I need to show all available rooms at the moment. I have two tables room and reservation . They are connected many to many from table RoomReservation.
public class Room
{
public int Id { get; set; }
public double CostNight { get; set; }
public virtual ICollection<Reservation> Reservation { get; set; }
}
public class Reservation
{
public int Id { get; set; }
public string DateOfEntry { get; set; }
public int NumberOfNights { get; set; }
public virtual ICollection<Room> Room { get; set; }
}
I tried to write:
public IEnumerable<Room> GetRooms(int title, DateTime? datepicker)
{
return context.Room.Where(x => x.Booking.Count == 0 ||
x.Booking.All(b => b.DateOfEntry > datepicker || (b.DateOfEntry < DbFunctions.AddDays(datepicker, b.NumberOfNights))))
.Where(x=>x.Categoryid == title);
}
datepicker - date selected by the Client. title - category room(this i need too). DateOfEntry - date of arrival in the Room. But it does not work.
Also, if for example the client chose 2015-05-10 and book for 5 days, and the database is already have booked this number 2015-05-12 , need display a message..how to do it?Thanks!
Aucun commentaire:
Enregistrer un commentaire