Пример #1
0
        public async Task <SelectEmployerViewModel> Map(SelectEmployerRequest source)
        {
            List <AccountProviderLegalEntityViewModel> accountProviderLegalEntities = await GetAccountProviderLegalEntities(source);

            var filterModel = new SelectEmployerFilterModel
            {
                SearchTerm             = source.SearchTerm,
                ReverseSort            = source.ReverseSort,
                CurrentlySortedByField = source.SortField,
                Employers = accountProviderLegalEntities.Select(x => x.EmployerAccountLegalEntityName + " - " + x.EmployerAccountName).ToList()
            };

            accountProviderLegalEntities = ApplySearch(source, accountProviderLegalEntities, filterModel);

            accountProviderLegalEntities = ApplySort(accountProviderLegalEntities, filterModel);

            return(new SelectEmployerViewModel
            {
                AccountProviderLegalEntities = accountProviderLegalEntities,
                ProviderId = source.ProviderId,
                SelectEmployerFilterModel = filterModel
            });
        }
Пример #2
0
        private static List <AccountProviderLegalEntityViewModel> ApplySearch(SelectEmployerRequest source, List <AccountProviderLegalEntityViewModel> accountProviderLegalEntities, SelectEmployerFilterModel filterModel)
        {
            if (!string.IsNullOrWhiteSpace(source.SearchTerm))
            {
                if (!string.IsNullOrWhiteSpace(filterModel.SearchAccountName))
                {
                    accountProviderLegalEntities = accountProviderLegalEntities.Where(x => x.EmployerAccountLegalEntityName.ToLower().Contains(filterModel.SearchEmployerName) &&
                                                                                      x.EmployerAccountName.ToLower().Contains(filterModel.SearchAccountName)).ToList();
                }
                else
                {
                    accountProviderLegalEntities = accountProviderLegalEntities.Where(x => x.EmployerAccountName.ToLower().Contains(filterModel.SearchEmployerName)
                                                                                      ||
                                                                                      x.EmployerAccountLegalEntityName.ToLower().Contains(filterModel.SearchEmployerName)).ToList();
                }
            }

            return(accountProviderLegalEntities);
        }
Пример #3
0
        private static List <AccountProviderLegalEntityViewModel> ApplySort(List <AccountProviderLegalEntityViewModel> accountProviderLegalEntities, SelectEmployerFilterModel filterModel)
        {
            if (!string.IsNullOrWhiteSpace(filterModel.CurrentlySortedByField))
            {
                if (filterModel.CurrentlySortedByField == SelectEmployerFilterModel.EmployerAccountLegalEntityNameConst)
                {
                    accountProviderLegalEntities = (filterModel.ReverseSort
                        ? accountProviderLegalEntities.OrderByDescending(x => x.EmployerAccountLegalEntityName)
                                                    .ThenBy(x => x.EmployerAccountName)
                                                    .ThenBy(x => x.EmployerAccountLegalEntityPublicHashedId)

                        : accountProviderLegalEntities.OrderBy(x => x.EmployerAccountLegalEntityName)
                                                    .ThenBy(x => x.EmployerAccountName)
                                                    .ThenBy(x => x.EmployerAccountLegalEntityPublicHashedId)).ToList();
                }
                else
                {
                    accountProviderLegalEntities = (filterModel.ReverseSort
                     ? accountProviderLegalEntities.OrderByDescending(x => x.EmployerAccountName)
                                                    .ThenBy(x => x.EmployerAccountLegalEntityName)
                                                    .ThenBy(x => x.EmployerAccountLegalEntityPublicHashedId)

                     : accountProviderLegalEntities.OrderBy(x => x.EmployerAccountName)
                                                    .ThenBy(x => x.EmployerAccountLegalEntityName)
                                                    .ThenBy(x => x.EmployerAccountLegalEntityPublicHashedId)).ToList();
                }
            }

            return(accountProviderLegalEntities);
        }