예제 #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);
        }
예제 #2
0
        public static coreModel.SearchCriteria ToCoreModel(this webModel.SearchCriteria criteria)
        {
            var retVal = new coreModel.SearchCriteria();

            retVal.InjectFrom(criteria);
            return(retVal);
        }
예제 #3
0
        public IHttpActionResult ListOrganizations()
        {
            var searchCriteria = new coreModel.SearchCriteria
            {
                MemberType = typeof(coreModel.Organization).Name,
                DeepSearch = true,
                Take       = int.MaxValue
            };
            var result = _memberService.SearchMembers(searchCriteria);

            return(Ok(result.Members));
        }
        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();
            }
        }
        public IHttpActionResult Search(coreModel.SearchCriteria criteria)
        {
            var result = _contactSearchService.Search(criteria);

            var retVal = new webModel.SearchResult();

            var start = criteria.Skip;
            var count = criteria.Take;

            // all organizations
            var organizations = result.Organizations.Select(x => x.ToWebModel());
            var contacts      = result.Contacts.Select(x => x.ToWebModel());

            retVal.TotalCount = organizations.Count() + result.TotalCount;
            retVal.Members.AddRange(organizations.Skip(start).Take(count));

            count -= organizations.Count();

            retVal.Members.AddRange(contacts.Take(count));

            return(Ok(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));
                }
                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();
            }
        }
예제 #10
0
        public IHttpActionResult Search(coreModel.SearchCriteria criteria)
        {
            var result = _memberService.SearchMembers(criteria);

            return(Ok(result));
        }
예제 #11
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;
            }
        }
예제 #12
0
        public IHttpActionResult ListOrganizations()
        {
            var searchCriteria = new coreModel.SearchCriteria
            {
                MemberType = typeof(coreModel.Organization).Name,
                DeepSearch = true,
                Take = int.MaxValue
            };
            var result = _memberService.SearchMembers(searchCriteria);

            return Ok(result.Members);
        }
		public static coreModel.SearchCriteria ToCoreModel(this webModel.SearchCriteria criteria)
		{
			var retVal = new coreModel.SearchCriteria();
			retVal.InjectFrom(criteria);
			return retVal;
		}