public IEnumerable <ReservationDao> SearchReservations(string membershipId, string email, string code, DateTime dateReservedFrom, DateTime dateReservedTo, bool isConfirmed) { if (dateReservedFrom.Equals(DateTime.MinValue)) { dateReservedFrom = new DateTime(1900, 1, 1); } if (dateReservedTo.Equals(DateTime.MinValue)) { dateReservedTo = new DateTime(1900, 1, 1); } ObjectResult <sp_search_reservations_Result> result = entities.sp_search_reservations(membershipId, email, code, dateReservedFrom, dateReservedTo, isConfirmed); List <ReservationDao> reservations = new List <ReservationDao>(); foreach (sp_search_reservations_Result dbReservation in result) { if (dbReservation.date_confirmed != null && dbReservation.date_returned != null) { reservations.Add(new ReservationDao(dbReservation.id, dbReservation.date_reserved_from, dbReservation.date_reserved_to, dbReservation.code, (DateTime)dbReservation.date_confirmed, true, (DateTime)dbReservation.date_returned, true, dbReservation.membership_id, dbReservation.isbn, dbReservation.confirmed_by_membership_id, dbReservation.returned_to_user_membership_id)); } else if (dbReservation.date_confirmed != null) { reservations.Add(new ReservationDao(dbReservation.id, dbReservation.date_reserved_from, dbReservation.date_reserved_to, dbReservation.code, (DateTime)dbReservation.date_confirmed, true, false, dbReservation.membership_id, dbReservation.isbn, dbReservation.confirmed_by_membership_id, dbReservation.returned_to_user_membership_id)); } else { reservations.Add(new ReservationDao(dbReservation.id, dbReservation.date_reserved_from, dbReservation.date_reserved_to, dbReservation.code, false, false, dbReservation.membership_id, dbReservation.isbn, dbReservation.confirmed_by_membership_id, dbReservation.returned_to_user_membership_id)); } } return(reservations); }