Example #1
0
        public coreModel.SearchResult Search(coreModel.SearchCriteria criteria)
        {
            coreModel.SearchResult retVal;
            using (var repository = _repositoryFactory())
            {
                var query = repository.Members.OrderBy(x => x.CreatedDate).OfType <foundationModel.Contact>().Select(x => x.Id);

                retVal = new coreModel.SearchResult
                {
                    TotalCount = query.Count(),
                    Contacts   = new List <coreModel.Contact>()
                };

                foreach (var contactId in query.Skip(criteria.Start).Take(criteria.Count).ToArray())
                {
                    var contact = repository.GetContactById(contactId);
                    if (contact != null)
                    {
                        retVal.Contacts.Add(contact.ToCoreModel());
                    }
                }
            }

            return(retVal);
        }
		public coreModel.SearchResult Search(coreModel.SearchCriteria criteria)
		{
			var retVal = new coreModel.SearchResult();
			var taskList = new List<Task>();

			taskList.Add(Task.Factory.StartNew(() => SearchOrganizations(criteria, retVal)));
			taskList.Add(Task.Factory.StartNew(() => SearchContacts(criteria, retVal)));
	
			Task.WaitAll(taskList.ToArray());

			return retVal;
		}
        public coreModel.SearchResult Search(coreModel.SearchCriteria criteria)
        {
            var retVal   = new coreModel.SearchResult();
            var taskList = new List <Task>();

            taskList.Add(Task.Factory.StartNew(() => SearchOrganizations(criteria, retVal)));
            taskList.Add(Task.Factory.StartNew(() => SearchContacts(criteria, retVal)));

            Task.WaitAll(taskList.ToArray());

            return(retVal);
        }
        private void SearchContacts(coreModel.SearchCriteria criteria, coreModel.SearchResult result)
        {
            using (var repository = _repositoryFactory())
            {
                var query = repository.Members.OfType <foundationModel.Contact>();

                if (criteria.OrganizationId != null)
                {
                    query = query.Where(x => x.MemberRelations.Any(y => y.AncestorId == criteria.OrganizationId));
                    if (!String.IsNullOrEmpty(criteria.Keyword))
                    {
                        query = query.Where(x => x.FullName.Contains(criteria.Keyword));
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(criteria.Keyword))
                    {
                        query = query.Where(x => x.FullName.Contains(criteria.Keyword) || x.Emails.Any(y => y.Address.Contains(criteria.Keyword)));
                    }
                    else
                    {
                        query = query.Where(x => !x.MemberRelations.Any());
                    }
                }

                result.TotalCount = query.Count();

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = "FullName"
                                        } };
                }
                //Try to replace sorting columns names
                TryTransformSortingInfoColumnNames(_contactSortingAliases, sortInfos);
                query = query.OrderBySortInfos(sortInfos);

                result.Contacts = query.Skip(criteria.Skip)
                                  .Take(criteria.Take)
                                  .ToArray()
                                  .Select(x => x.ToCoreModel())
                                  .ToList();
            }
        }
        private void SearchOrganizations(coreModel.SearchCriteria criteria, coreModel.SearchResult result)
        {
            using (var repository = _repositoryFactory())
            {
                var query = repository.Organizations;
                if (criteria.OrganizationId != null)
                {
                    query = query.Where(x => x.MemberRelations.Any(y => y.AncestorId == criteria.OrganizationId));
                    if (!String.IsNullOrEmpty(criteria.Keyword))
                    {
                        query = query.Where(x => x.Name.Contains(criteria.Keyword));
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(criteria.Keyword))
                    {
                        query = query.Where(x => x.Name.Contains(criteria.Keyword));
                    }
                    else
                    {
                        query = query.Where(x => !x.MemberRelations.Any());
                    }
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = "Name"
                                        } };
                }
                //Try to replace sorting columns names
                TryTransformSortingInfoColumnNames(_organizationSortingAliases, sortInfos);
                query = query.OrderBySortInfos(sortInfos);


                result.Organizations = query.ToArray()
                                       .Select(x => x.ToCoreModel())
                                       .ToList();
            }
        }
        private void SearchOrganizations(coreModel.SearchCriteria criteria, coreModel.SearchResult result)
        {
            using (var repository = _repositoryFactory())
            {
                var query = repository.Organizations;
                if (criteria.OrganizationId != null)
                {
                    query = query.Where(x => x.MemberRelations.Any(y => y.AncestorId == criteria.OrganizationId));
                }
                else
                {
                    query = query.Where(x => !x.MemberRelations.Any());
                }

                result.Organizations = query.OrderByDescending(x => x.Name)
                                       .ToArray()
                                       .Select(x => x.ToCoreModel())
                                       .ToList();
            }
        }
        private void SearchContacts(coreModel.SearchCriteria criteria, coreModel.SearchResult result)
        {
            using (var repository = _repositoryFactory())
            {
                var query = repository.Members.OfType <foundationModel.Contact>();
                if (criteria.OrganizationId != null)
                {
                    query = query.Where(x => x.MemberRelations.Any(y => y.AncestorId == criteria.OrganizationId));
                }
                else
                {
                    query = query.Where(x => !x.MemberRelations.Any());
                }

                result.TotalCount = query.Count();

                result.Contacts = query.OrderBy(x => x.FullName)
                                  .Skip(criteria.Start)
                                  .Take(criteria.Count)
                                  .ToArray()
                                  .Select(x => x.ToCoreModel())
                                  .ToList();
            }
        }
        public coreModel.SearchResult Search(coreModel.SearchCriteria criteria)
        {
            coreModel.SearchResult retVal;
            using (var repository = _repositoryFactory())
            {
                var query = repository.Members.OrderBy(x => x.CreatedDate).OfType<foundationModel.Contact>().Select(x => x.Id);

                retVal = new coreModel.SearchResult
                {
                    TotalCount = query.Count(),
                    Contacts = new List<coreModel.Contact>()
                };

                foreach (var contactId in query.Skip(criteria.Start).Take(criteria.Count).ToArray())
                {
                    var contact = repository.GetContactById(contactId);
                    if (contact != null)
                    {
                        retVal.Contacts.Add(contact.ToCoreModel());
                    }
                }
            }

            return retVal;
        }
Example #9
0
        public SearchResult SearchMembers(SearchCriteria criteria)
        {
            var retVal = new SearchResult();

            using (var repository = _repositoryFactory())
            {
                var query = repository.Members;
                if (criteria.MemberType != null)
                {
                    query = query.Where(x => x.MemberType == criteria.MemberType || x.MemberType == null);
                }

                if (criteria.MemberId != null)
                {
                    //TODO: DeepSearch in specified member
                    query = query.Where(x => x.MemberRelations.Any(y => y.AncestorId == criteria.MemberId));
                }
                else
                {
                    if (!criteria.DeepSearch)
                    {
                        query = query.Where(x => !x.MemberRelations.Any());
                    }
                }

                if (!String.IsNullOrEmpty(criteria.Keyword))
                {
                    var contactQuery = query.OfType<dataModel.Contact>().Where(x => x.FullName.Contains(criteria.Keyword) || x.Emails.Any(y => y.Address.Contains(criteria.Keyword))).Select(x => x.Id).ToArray();
                    var orgQuery = query.OfType<dataModel.Organization>().Where(x => x.Name.Contains(criteria.Keyword)).Select(x => x.Id).ToArray();
                    var ids = contactQuery.Concat(orgQuery).ToArray();
                    query = query.Where(x => ids.Contains(x.Id));
                }

                retVal.TotalCount = query.Count();

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo { SortColumn = "Name" } };
                }
                //Workaround - need display organization first (OrderByDescending(x => x.MemberType))
                query = query.OrderByDescending(x => x.MemberType).ThenBySortInfos(sortInfos);

                retVal.Members = query.Skip(criteria.Skip)
                                      .Take(criteria.Take)
                                      .ToArray()
                                      .Select(x => ConvertToMember(x))
                                      .ToList();
                return retVal;
            }
        }