예제 #1
0
 public ActionResult ListSortedCompanies(CompanyFilterViewModel filter)
 {
     if (ModelState.IsValid)
     {
         return(Ok(_companyService.Filter(filter)));
     }
     return(null);
 }
예제 #2
0
        public Companies()
        {
            NavigationPage.SetBackButtonTitle(this, "");
            InitializeComponent();

            //HockeyApp.MetricsManager.TrackEvent("SubmitTimeSheetPage Initialize");

            viewModel      = new CompanyFilterViewModel();
            BindingContext = viewModel;
            LoadData();
        }
예제 #3
0
        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));
        }