Beispiel #1
0
        public ActionResult Search(OrganisationSearchCriteria criteria, [Bind(Include = "VerifiedOrganisations")] CheckBoxValue verifiedOrganisations, [Bind(Include = "UnverifiedOrganisations")] CheckBoxValue unverifiedOrganisations)
        {
            var accountManagers = _administratorsQuery.GetAdministrators();

            criteria.VerifiedOrganisations   = verifiedOrganisations.IsChecked;
            criteria.UnverifiedOrganisations = unverifiedOrganisations.IsChecked;
            var organisations = _executeOrganisationSearchCommand.Search(criteria);

            return(View(new OrganisationSearchModel
            {
                Criteria = criteria,
                AccountManagers = accountManagers,
                Organisations = organisations,
            }));
        }
        private IList <Employer> Search(AdministrativeEmployerSearchCriteria criteria)
        {
            // Get all organisations that match the criteria.

            IEnumerable <Employer>           contacts;
            IDictionary <Guid, Organisation> contactOrganisations;

            if (!string.IsNullOrEmpty(criteria.OrganisationName))
            {
                // Get all the employers that match the other criteria.

                var originalCount = criteria.Count;
                criteria.Count = null;

                contacts = _repository.Search(criteria);

                // Search for the matching organisations.

                var organisationsCriteria = new OrganisationSearchCriteria
                {
                    FullName                = criteria.OrganisationName,
                    MatchFullNameExactly    = criteria.MatchOrganisationNameExactly,
                    UnverifiedOrganisations = true,
                    VerifiedOrganisations   = true,
                };

                var organisations = _executeOrganisationSearchCommand.Search(organisationsCriteria);

                // Filter the contacts out by organisations.

                contactOrganisations = _recruitersQuery.GetOrganisations(from c in contacts select c.Id, from o in organisations select o.Id);
                contacts             = from c in contacts
                                       where contactOrganisations.ContainsKey(c.Id)
                                       select c;

                if (originalCount != null)
                {
                    contacts = contacts.Take(originalCount.Value);
                }
            }
            else
            {
                // Pass it through to the repository.

                contacts             = _repository.Search(criteria);
                contactOrganisations = _recruitersQuery.GetOrganisations(from c in contacts select c.Id);
            }

            // Set up the organisations.

            contacts = from c in contacts
                       select GetEmployer(c, contactOrganisations);

            // Order now.

            if (criteria.SortOrder == EmployerSortOrder.OrganisationNameLoginId)
            {
                return((from c in contacts
                        orderby c.Organisation.Name, c.EmailAddress.Address // c.LoginId
                        select c).ToList());
            }

            return((from c in contacts
                    orderby c.EmailAddress.Address // c.LoginId
                    select c).ToList());
        }
Beispiel #3
0
        IList <Organisation> IRecruitersRepository.Search(OrganisationSearchCriteria criteria)
        {
            using (var dc = CreateContext().AsReadOnly())
            {
                dc.LoadOptions = OrganisationLoadOptions;

                // Do two separate queries against each of the verified and unverified organisations.

                IQueryable <Organisation> organisations = null;

                if (criteria.VerifiedOrganisations)
                {
                    // Look for verified organisations.

                    var query = from o in dc.OrganisationEntities
                                where o.OrganisationalUnitEntity != null
                                select o;

                    if (criteria.AccountManagerId != null)
                    {
                        query = from o in query
                                where o.OrganisationalUnitEntity.accountManagerId == criteria.AccountManagerId.Value
                                select o;
                    }

                    // Match the full name.

                    if (!string.IsNullOrEmpty(criteria.FullName))
                    {
                        if (criteria.MatchFullNameExactly)
                        {
                            query = from o in query
                                    where dc.GetOrganisationFullName(o.id, null) == criteria.FullName
                                    select o;
                        }
                        else
                        {
                            query = from o in query
                                    where SqlMethods.Like(dc.GetOrganisationFullName(o.id, null), criteria.FullName + '%')
                                    select o;
                        }
                    }

                    organisations = from o in query
                                    select o.Map(dc.GetOrganisationFullName(o.OrganisationalUnitEntity.parentId, null), _locationQuery);
                }

                if (criteria.UnverifiedOrganisations)
                {
                    // If the account manager is set then don't return anything.

                    if (criteria.AccountManagerId == null)
                    {
                        // Look for unverified organisations.

                        var query = from o in dc.OrganisationEntities
                                    where o.OrganisationalUnitEntity == null
                                    select o;

                        // Match the name.

                        if (!string.IsNullOrEmpty(criteria.FullName))
                        {
                            if (criteria.MatchFullNameExactly)
                            {
                                query = from o in query
                                        where o.displayName == criteria.FullName
                                        select o;
                            }
                            else
                            {
                                query = from o in query
                                        where SqlMethods.Like(o.displayName, criteria.FullName + '%')
                                        select o;
                            }
                        }

                        var unverifiedOrganisations = from o in query
                                                      select o.Map(dc.GetOrganisationFullName(o.OrganisationalUnitEntity.parentId, null), _locationQuery);

                        organisations = organisations == null
                                            ? unverifiedOrganisations
                                            : organisations.Concat(unverifiedOrganisations);
                    }
                }

                // Order by full name after all results have been returned from the database.

                return(organisations == null
                           ? new List <Organisation>()
                           : (from o in organisations.ToArray() orderby o.FullName select o).ToList());
            }
        }