public static IEnumerable <Tour> ListTours(string type = null, string value = null) { int valueInt; bool isNumeric = int.TryParse(value, out valueInt); return(TourDAL.Get( t => type == null || ( (type == "Id" && isNumeric && t.Id == valueInt) || (type == "Name" && t.Name.Contains(value.Trim())) || (type == "Description" && t.Description.Contains(value.Trim())) || (type == "TourTypeName" && t.TourType.Name.Contains(value.Trim())) ), null, new List <Expression <Func <Tour, object> > > { t => t.TourType } )); }
public static IEnumerable <TourWithGroups> ListTourWithGroups(DateTime?StartDate = null, DateTime?EndDate = null) { try { if (StartDate.HasValue && EndDate.HasValue) { new DateRange(StartDate.Value, EndDate.Value); } var listTours = TourDAL.Get(); var listTourWithGroups = listTours.Select(t => new TourWithGroups { Tour = t }).ToList(); //Check filter date in this listGroups; var listGroups = GroupDAL.Get( filter: g => (!StartDate.HasValue || !EndDate.HasValue) || (StartDate.Value <= g.StartDate && g.StartDate <= EndDate.Value), includeProperties: new List <Expression <Func <Group, object> > > { g => g.Tour, g => g.Costs, g => g.CustomerGroups, } ).ToList(); foreach (var group in listGroups) { int foundIndex = listTourWithGroups.FindIndex(ele => ele.Tour.Id == group.Tour.Id); if (foundIndex != -1) { listTourWithGroups[foundIndex].Groups.Add(group); } } return(listTourWithGroups); } catch (Exception ex) { throw ex; } }