public bool IsClassRoomAvailable(string classroomDay, DateTime classroomFromTime, DateTime classroomToTime, int roomId) { var rooms = _classRoomGateway.GetAllAllocatedClassRoom().Where(c => c.Day.ToLower() == classroomDay.ToLower() && c.RoomId == roomId).ToList(); foreach (var room in rooms) { string fromtimeDb = room.FromTime.ToString("HH.mm"); string totimeDb = room.ToTime.ToString("HH.mm"); string usrFrmTime = classroomFromTime.ToString("HH.mm"); string usrToTime = classroomToTime.ToString("HH.mm"); double fu = Convert.ToDouble(usrFrmTime); double tu = Convert.ToDouble(usrToTime); double fd = Convert.ToDouble(fromtimeDb); double td = Convert.ToDouble(totimeDb); if ((fu < fd && fu < td) && (tu < td && tu > fd)) { return(false); } else if ((fu == fd && fu < td) || (tu == td && tu > fd)) { return(false); } else if ((fu < fd && fu < td) && (tu < td && tu > fd )) { return(false); } else if ((fu < fd && fu < td) && (tu > fd && tu > td)) { return(false); } else if ((fu > fd && fu < td) && (tu > fd && tu > td)) { return(false); } } return(true); }