Пример #1
0
        private DetachedCriteria QuickSearch(UserSearch userSearch)
        {
            DetachedCriteria result = CreateDetachedCriteria().CreateAlias("Contact", "contact");


            Disjunction userInfo  = Restrictions.Disjunction();
            bool        inSercher = false;


            if (!string.IsNullOrEmpty(userSearch.Login))
            {
                inSercher = true;
                userInfo.Add(Restrictions.InsensitiveLike(LoginProperty, userSearch.Login));
            }

            if (!string.IsNullOrEmpty(userSearch.Name))
            {
                string searchContent = userSearch.Name;
                if (!searchContent.Contains("%"))
                {
                    searchContent = "%" + searchContent + "%";
                }
                inSercher = true;
                userInfo.Add(Restrictions.InsensitiveLike(NameProperty, searchContent));
            }


            if (!string.IsNullOrEmpty(userSearch.Email))
            {
                string searchContent = userSearch.Email;
                if (!searchContent.Contains("%"))
                {
                    searchContent = "%" + searchContent + "%";
                }
                inSercher = true;
                userInfo.Add(Restrictions.InsensitiveLike(ContactEmailProperty("contact"), searchContent));
            }

            if (!string.IsNullOrEmpty(userSearch.Phone))
            {
                string searchContent = userSearch.Phone;
                if (!searchContent.Contains("%"))
                {
                    searchContent = "%" + searchContent + "%";
                }
                inSercher = true;
                userInfo.Add(Restrictions.InsensitiveLike(ContactPhoneProperty("contact"), searchContent));
            }

            if (userSearch.Org != null)
            {
                inSercher = true;
                string max;
                string min;
                result.CreateAlias("Org", "org");
                Org.CreateGetChildCondition(userSearch.Org, out max, out min);
                userInfo.Add(
                    Restrictions.Disjunction()
                    .Add(Restrictions.Eq("org.OrderId", userSearch.Org.Id)).Add(
                        Restrictions.Conjunction()
                        .Add(Restrictions.Le("org.OrderId", max))
                        .Add(Restrictions.Ge("org.OrderId", min))));
            }
            if (inSercher)
            {
                result.Add(userInfo);
            }
            return(result);
        }