public SmallGroupSearchResult getGroups() { if (_search == null) { return(new SmallGroupSearchResult { Organizations = new List <Organization>(), IsInitialSearch = true }); } var orgTypes = OrgTypes.Split(',').Select(x => x.Trim()).Where(x => !string.IsNullOrEmpty(x)).ToList(); IQueryable <Organization> orgs; if (!orgTypes.Any()) { orgs = from o in DbUtil.Db.Organizations where o.OrganizationStatusId == 30 && o.DivOrgs.Any(ee => _divList.Contains(ee.DivId)) select o; } else { orgs = from o in DbUtil.Db.Organizations where o.OrganizationStatusId == 30 && orgTypes.Contains(o.OrganizationType.Description) select o; } foreach (var filter in _search) { if (filter.Value.values.Contains(SHOW_ALL)) { continue; } if (filter.Key == "Campus") { orgs = from g in orgs where g.Campu.Description == filter.Value.values[0] select g; } else if (filter.Key.EndsWith("Time")) { var val = filter.Value.values[0]; orgs = from g in orgs where g.OrganizationExtras .Any(oe => oe.Field == filter.Key && ( oe.StrValue.ToLower().EndsWith(val) || oe.Data.ToLower().EndsWith(val) || oe.DateValue != null && oe.DateValue.ToString().EndsWith(val) || oe.IntValue != null && oe.IntValue.ToString().EndsWith(val) || oe.BitValue != null && oe.BitValue.ToString().EndsWith(val) ) ) select g; } else if (filter.Value.parse) { var vals = filter.Value.values; orgs = from g in orgs where g.OrganizationExtras .Any(oe => oe.Field == filter.Key && ( vals.Contains(oe.StrValue) || vals.Contains(oe.Data) || oe.DateValue != null && vals.Contains(oe.DateValue.ToString()) || oe.IntValue != null && vals.Contains(oe.IntValue.ToString()) || oe.BitValue != null && vals.Contains(oe.BitValue.ToString()) ) ) select g; } else { var val = filter.Value.values[0]; orgs = from g in orgs where g.OrganizationExtras .Any(oe => oe.OrganizationId == g.OrganizationId && oe.Field == filter.Key && ( oe.StrValue == val || oe.Data.ToLower() == val || oe.DateValue != null && oe.DateValue.ToString() == val || oe.IntValue != null && oe.IntValue.ToString() == val || oe.BitValue != null && oe.BitValue.ToString() == val ) ) select g; } } return(new SmallGroupSearchResult { Organizations = orgs.OrderBy(gg => gg.OrganizationName).ToList(), IsInitialSearch = false }); }
public List <FilterItem> getFilterItems(int id) { var f = getFilter(id); var i = new List <FilterItem>(); var orgTypes = OrgTypes.Split(',').Select(x => x.Trim()).Where(x => !string.IsNullOrEmpty(x)); if (f.locked) { i.Add(new FilterItem { value = f.lockedvalue }); } else { if (f.weekdays) { i.AddRange(weekdayList.Select(w => new FilterItem { value = w })); } else if (f.timeofdayonly) { i.AddRange(new[] { "AM", "PM" }.Select(x => new FilterItem { value = x })); } else if (f.name == "Campus") { var campusExclusions = f.exclude?.Split(',') ?? new string[] { }; i = (from campus in DbUtil.Db.Campus orderby campus.Description where !campusExclusions.Contains(campus.Description) select new FilterItem { value = campus.Description }).ToList(); } else { var orgExcludes = f.name == "Group Type" || f.name == "SGF:Type" ? (f.exclude?.Split(',') ?? new string[] { }) : new string[] { }; i = (from e in DbUtil.Db.OrganizationExtras where e.Organization.DivOrgs.Any(ee => _divList.Contains(ee.DivId)) || orgTypes.Contains(e.Organization.OrganizationType.Description) where !orgExcludes.Contains(e.StrValue) where e.Field == f.name orderby e.Data ?? e.StrValue ?? (e.DateValue != null ? e.DateValue.ToString() : null) ?? (e.IntValue != null ? e.IntValue.ToString() : null) ?? (e.BitValue != null ? e.BitValue.ToString() : null) select e) .ToList() .Select(x => new FilterItem { value = x.Data ?? x.StrValue ?? x.DateValue?.ToString() ?? x.IntValue?.ToString() ?? x.BitValue?.ToString() }).DistinctBy(n => n.value).ToList(); } i.Insert(0, new FilterItem { value = SHOW_ALL }); } return(i); }