public ActionResult ListSortedCompanies(CompanyFilterViewModel filter) { if (ModelState.IsValid) { return(Ok(_companyService.Filter(filter))); } return(null); }
public Companies() { NavigationPage.SetBackButtonTitle(this, ""); InitializeComponent(); //HockeyApp.MetricsManager.TrackEvent("SubmitTimeSheetPage Initialize"); viewModel = new CompanyFilterViewModel(); BindingContext = viewModel; LoadData(); }
public IEnumerable <CompanyViewModel> Filter(CompanyFilterViewModel filter) { IEnumerable <Company> result = Database.Companies.GetAll().Include(company => company.CompanyAppUsers); // sort by location if (!string.IsNullOrEmpty(filter.Location)) { result = result.Where(company => !String.IsNullOrEmpty(company.Location) && company.Location.Trim().ToLowerInvariant().Contains(filter.Location.Trim().ToLowerInvariant())); } // sort by industry if (!string.IsNullOrEmpty(filter.Industry)) { result = result.Where(company => company.Industry.GetDescription().Trim().ToLowerInvariant() == filter.Industry.Trim().ToLowerInvariant()); } // sort by company size if (filter.MinCompanySize != 0 || filter.MaxCompanySize != 0) { if (filter.MaxCompanySize == 0) { // select from min to infinity result = result.Where(company => company.CompanyAppUsers.Count(companyAppUser => companyAppUser.CompanyId == company.Id) >= filter.MinCompanySize); } else { // select from min to max result = result.Where(company => company.CompanyAppUsers.Count(companyAppUser => companyAppUser.CompanyId == company.Id) >= filter.MinCompanySize && company.CompanyAppUsers.Count(companyAppUser => companyAppUser.CompanyId == company.Id) <= filter.MaxCompanySize); } } return(Mapping.Map <IEnumerable <Company>, IEnumerable <CompanyViewModel> >(result)); }