public static List <ResortModel> ApplyFilter() { var result = Resorts.Where(resort => resort.Rating >= Filter.MinRating && resort.Rating <= Filter.MaxRating); if (!string.IsNullOrEmpty(Filter.Location)) { result = result.Where(resort => resort.Location == Filter.Location); } var diseases = Mapper.Map <List <DiseaseModel> >(Filter.Diseases.Where(disease => disease.IsChecked)); if (diseases.Any()) { result = result.Where(resort => resort.Diseases.Select(disease => disease.Name).Intersect(diseases.Select(disease => disease.Name)).Any()); } if (Filter.IsSanatorium) { result = result.Where(resort => resort.IsSanatorium); } if (Filter.Season != SeasonEnum.Any) { result = result.Where(resort => resort.Seasons.Contains(Filter.Season)); } return(result.ToList()); }
public override void FiltrByBedNumber() { if (BedNumber > 0) { if (Resorts != null) { List <HolidayHome> list = Resorts.SelectMany(r => r.HolidayHomes).Where(h => h.numberofBeds == BedNumber).ToList(); List <Resort> listresort = list.Select(l => l.Resort).ToList(); Resorts = listresort.AsEnumerable <Resort>().Distinct().ToList(); List <Room> listroom = Resorts.SelectMany(r => r.Rooms).Where(h => h.numberofBeds == BedNumber).ToList(); List <Resort> listresort2 = list.Select(l => l.Resort).ToList(); Resorts.AddRange(listresort2); Resorts = Resorts.AsEnumerable <Resort>().Distinct().ToList(); } if (Hotels != null) { List <Room> list = Hotels.SelectMany(r => r.Rooms).Where(h => h.numberofBeds == BedNumber).ToList(); List <Hotel> listhotel = list.Select(l => l.Hotel).ToList(); Hotels = listhotel.AsEnumerable <Hotel>().Distinct().ToList(); } } }
public override void FiltrByDate() { if (Resorts != null) { List <HolidayHome> HolidayHomes = Resorts.SelectMany(x => x.HolidayHomes).ToList(); List <HolidayHome> listofHolidayHomes = new List <HolidayHome>(HolidayHomes); List <DateTime> timeinterval = new List <DateTime>(); if (BookFrom == DateTime.MinValue) { BookFrom = DateTime.Now.AddDays(1); } if (BookTo == DateTime.MinValue) { BookTo = BookFrom.AddMonths(1); } int nightsCount = (int)Math.Round((BookTo - BookFrom).TotalDays); for (int i = 0; i < nightsCount; i++) { DateTime dayinter = BookFrom; dayinter = dayinter.AddHours(16); dayinter = dayinter.AddDays(i); timeinterval.Add(dayinter); } foreach (var holidayhome in HolidayHomes) { foreach (var reservetime in holidayhome.reserveTimes) { foreach (var day in timeinterval) { if (day >= reservetime.bookingFrom && day <= reservetime.bookingToo) { listofHolidayHomes.Remove(holidayhome); } } } } List <Resort> listresort2 = listofHolidayHomes.Select(l => l.Resort).ToList(); ///////// List <Room> Rooms = Resorts.SelectMany(h => h.Rooms).ToList(); List <Room> listofRooms = new List <Room>(Rooms); List <DateTime> timeinterval2 = new List <DateTime>(); if (BookFrom == null) { BookFrom = DateTime.Now.AddDays(1); } if (BookTo == null) { BookTo = BookFrom.AddMonths(1); } int nightsCount2 = (int)Math.Round((BookTo - BookFrom).TotalDays); for (int i = 0; i < nightsCount2; i++) { DateTime dayinter = BookFrom; dayinter = dayinter.AddHours(16); dayinter = dayinter.AddDays(i); timeinterval2.Add(dayinter); } foreach (var room in Rooms) { foreach (var reservetime in room.reserveTimes) { foreach (var day in timeinterval2) { if (day >= reservetime.bookingFrom && day <= reservetime.bookingToo) { listofRooms.Remove(room); } } } } Rooms = listofRooms; List <Resort> listofResorts = Rooms.Select(x => x.Resort).ToList(); Resorts = new List <Resort>(); Resorts.AddRange(listofResorts); Resorts.AddRange(listresort2); Resorts = Resorts.AsEnumerable <Resort>().Distinct().ToList(); if (Rooms != null && Rooms.Count > 0) { foreach (var resort in Resorts) { List <Room> listDictionary = new List <Room>(); foreach (var room in listofRooms) { if (resort.Rooms.Contains(room)) { listDictionary.Add(room); } } ResortListOfRooms.Add(resort, listDictionary); listDictionary = new List <Room>(); } } if (HolidayHomes != null && HolidayHomes.Count > 0) { foreach (var resort in Resorts) { List <HolidayHome> listDictionary = new List <HolidayHome>(); foreach (var holidayhome in listofHolidayHomes) { if (resort.HolidayHomes.Contains(holidayhome)) { listDictionary.Add(holidayhome); } } ResortListOfHolidayHomes.Add(resort, listDictionary); } } ///////// } if (Hotels != null) { List <Room> Rooms = Hotels.SelectMany(h => h.Rooms).ToList(); List <Room> listofRooms = new List <Room>(Rooms); List <DateTime> timeinterval = new List <DateTime>(); if (BookFrom == null) { BookFrom = DateTime.Now.AddDays(1); } if (BookTo == null) { BookTo = BookFrom.AddMonths(1); } int nightsCount = (int)Math.Round((BookTo - BookFrom).TotalDays); for (int i = 0; i < nightsCount; i++) { DateTime dayinter = BookFrom; dayinter = dayinter.AddHours(16); dayinter = dayinter.AddDays(i); timeinterval.Add(dayinter); } foreach (var room in Rooms) { foreach (var reservetime in room.reserveTimes) { foreach (var day in timeinterval) { if (day >= reservetime.bookingFrom && day <= reservetime.bookingToo) { listofRooms.Remove(room); } } } } Rooms = listofRooms; Hotels = Hotels.AsEnumerable <Hotel>().Distinct().ToList(); if (Rooms != null && Rooms.Count > 0) { foreach (var hotel in Hotels) { List <Room> listDictionary = new List <Room>(); foreach (var room in Rooms) { if (hotel.Rooms.Contains(room)) { listDictionary.Add(room); } } HotelListOfRooms.Add(hotel, listDictionary); } } } }
public static ResortModel Get(int id) { return(Resorts.First(resort => resort.Id == id)); }
public static List <ResortModel> GetSponsored() { return(Resorts.Where(resort => resort.IsSponsored).ToList()); }