Esempio n. 1
0
        public IList <Campaign> GetActive(string applicationName, bool onlyFixed)
        {
            ICriteria crit = GetCriteria( );

            // Check Schedule Range
            Conjunction range = new Conjunction();

            range.Add(Expression.Le("StartDate", DateTime.Today));
            range.Add(Expression.Ge("EndDate", DateTime.Today));

            // If EndDate is null, avoid range check
            Disjunction nullDate = new Disjunction( );

            nullDate.Add(new NullExpression("EndDate"));
            nullDate.Add(range);

            // Apply filters
            crit.AddOrder(new Order("StartDate", false))
            .Add(Expression.Eq("Status", CampaignStatus.Enabled))
            .Add(Expression.Eq("ApplicationName", applicationName))
            .Add(nullDate);

            // If fixed only, check dynamic code is null
            if (onlyFixed)
            {
                crit.Add(new NullExpression("DynamicCode"));
            }

            return(crit.List <Campaign>( ));
        }
        private void FilterContentPublishedCriteria(ICriteria crit, ContentCategory cc, ContentType ct)
        {
            crit.Add(Expression.Eq("Category", cc));
            crit.Add(Expression.Eq("Type", ct));
            crit.Add(Expression.Eq("Status", ContentPublishedStatus.Enabled));

            Conjunction c1 = new Conjunction();

            c1.Add(Expression.Ge("ScheduleFrom", DateTime.Today));
            c1.Add(Expression.IsNull("ScheduleTo"));

            Conjunction c2 = new Conjunction();

            c2.Add(Expression.IsNull("ScheduleFrom"));
            c2.Add(Expression.IsNull("ScheduleTo"));

            Conjunction c3 = new Conjunction();

            c3.Add(Expression.Ge("ScheduleFrom", DateTime.Today));
            c3.Add(Expression.Le("ScheduleTo", DateTime.Today));

            Disjunction d = new Disjunction();

            d.Add(c1);
            d.Add(c2);
            d.Add(c3);

            crit.Add(d);

            crit.AddOrder(new Order("CreatedOn", false));
            crit.AddOrder(new Order("ScheduleFrom", false));
        }
Esempio n. 3
0
        internal override WalkedToken Walk(WalkedToken left, WalkedToken right)
        {
            Conjunction crit = new Conjunction();

            crit.Add(left.Criterion);
            crit.Add(right.Criterion);
            return(WalkedToken.FromCriterion(crit));
        }
Esempio n. 4
0
        internal override WalkedToken Walk(WalkedToken left, WalkedToken right)
        {
            Conjunction crit = new Conjunction();

            crit.Add(left.Criterion);
            crit.Add(right.Criterion);
            return WalkedToken.FromCriterion(crit);
        }
        private Conjunction FilterGarment(string[] searchlist, int number)
        {
            Conjunction c = new Conjunction();

            foreach (string s in searchlist)
            {
                c.Add(Expression.Or(Expression.InsensitiveLike(string.Format("garment{0}.Title", number), s, MatchMode.Anywhere), Expression.InsensitiveLike(string.Format("garment{0}.Keywords", number), s, MatchMode.Anywhere)));
            }

            c.Add(Expression.Not(Expression.Eq(string.Format("garment{0}.Id", number), 0)));

            return(c);
        }
Esempio n. 6
0
        public void SendClientSearchCriterionThatSearchesJustForASpecificClientId()
        {
            // Arrange
            const int expectedId = 2;
            Client    client     = new Client {
                Id = expectedId, FirstName = "Andre", LastName = "Multerer"
            };

            this._clientEditViewModel.ChangeToLoadedMode(client);

            Tuple <ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> criterion = null;

            Messenger.Default.Register <NotificationMessage <Tuple <ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> > >(this, x => criterion = x.Content);

            Conjunction clientConjunction = Restrictions.Conjunction();

            clientConjunction.Add(Restrictions.Where <Client>(c => c.Id == expectedId));
            Tuple <ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> expectedTuple = new Tuple <ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion>(clientConjunction, null, null);


            // Act
            this._clientEditViewModel.SendClientSearchCriterionMessage();

            // Assert
            criterion.Should().NotBeNull();
            criterion.ToString().Should().Be(expectedTuple.ToString());
        }
Esempio n. 7
0
        protected override Junction SetupWhere(ApplicationQuery request)
        {
            var junction = new Conjunction();

            if (!string.IsNullOrEmpty(request.InGameName))
            {
                junction.Add(Restrictions.Where(() => RootAlias.InGameName == request.InGameName));
            }

            if (request.Status.HasValue)
            {
                junction.Add(Restrictions.Where(() => RootAlias.Status == request.Status.Value));
            }

            return(junction);
        }
Esempio n. 8
0
        public override void VisitConditionalExpression(ConditionalExpression expr)
        {
            var visitorTrue = new SelectArgumentsVisitor <TResult>(parent);

            visitorTrue.VisitExpression(expr.IfTrue);

            var visitorFalse = new SelectArgumentsVisitor <TResult>(parent);

            visitorFalse.VisitExpression(expr.IfFalse);

            var visitorCondition = new WhereArgumentsVisitor(parent.RootCriteria);

            visitorCondition.VisitExpression(expr.Test);
            Conjunction conjunction = NHibernate.Expressions.Expression.Conjunction();

            foreach (var criterion in visitorCondition.CurrentCriterions)
            {
                conjunction.Add(criterion);
            }

            projections.Add(
                NHibernate.Expressions.Projections
                .Conditional(conjunction,
                             visitorTrue.ProjectionList,
                             visitorFalse.ProjectionList)
                );
        }
Esempio n. 9
0
        public void GetBillsByCriteriaForClientAndBill()
        {
            // Arrange
            const int quantity = 6;

            this.CreateRepositoryWithLoadedDatabase();
            this._repository.LoadDatabase(DatabaseFactory.TestFilePath);

            Conjunction billConjunction = Restrictions.Conjunction();

            billConjunction.Add(Restrictions.Where <Bill>(bill => bill.KindOfBill == ModelFactory.DefaultBillKindOfBill));

            Conjunction clientConjunction = Restrictions.Conjunction();

            clientConjunction.Add(Restrictions.Where <Client>(c => c.FirstName == ModelFactory.DefaultClientFirstName));

            // Act
            for (int i = 0; i < quantity; i++)
            {
                Bill bill = ModelFactory.GetDefaultBill();
                this._repository.SaveOrUpdate(bill.Client);
                this._repository.SaveOrUpdate(bill);
            }

            for (int i = 0; i < quantity; i++)
            {
                Bill bill = ModelFactory.GetDefaultBill();
                bill.Client.FirstName = "Manuel";
                this._repository.SaveOrUpdate(bill.Client);
                this._repository.SaveOrUpdate(bill);
            }

            // Assert
            this._repository.GetByCriteria <Bill, Client>(billConjunction, b => b.Client, clientConjunction, 1).Should().HaveCount(quantity);
        }
Esempio n. 10
0
        public void GetEmptyClientListWhenNoClientsEqualCriteria()
        {
            // Arrange
            this.CreateRepositoryWithLoadedDatabase();
            this._repository.LoadDatabase(DatabaseFactory.TestFilePath);

            Conjunction conjunction = Restrictions.Conjunction();

            conjunction.Add(Restrictions.Where <Client>(client => client.FirstName.IsLike("test", MatchMode.Anywhere)));

            // Act
            for (int i = 0; i < 5; i++)
            {
                Client client = new Client();
                this._repository.SaveOrUpdate(client);
            }

            for (int i = 0; i < 5; i++)
            {
                Client client = ModelFactory.GetDefaultClient();
                this._repository.SaveOrUpdate(client);
            }

            for (int i = 0; i < 5; i++)
            {
                Client client = new Client()
                {
                    FirstName = "Andreas"
                };
                this._repository.SaveOrUpdate(client);
            }

            // Assert
            this._repository.GetByCriteria <Client>(conjunction, 1).Should().HaveCount(0);
        }
Esempio n. 11
0
        public static QueryBuilder <T> operator |(QueryBuilder <T> lhs, QueryBuilder <T> rhs)
        {
            if (lhs.assoicationPath != rhs.assoicationPath)
            {
                throw new InvalidOperationException(
                          string.Format(
                              @"OR attempted between {0} and {1}.
You can't OR between two Query parts that belong to different assoications.
Use HQL for this functionality...",
                              lhs.assoicationPath,
                              rhs.assoicationPath));
            }

            QueryBuilder <T> combined        = new QueryBuilder <T>(lhs.name, null);
            Conjunction      lhs_conjunction = Expression.Conjunction();
            Conjunction      rhs_conjunction = Expression.Conjunction();

            foreach (ICriterion criterion in lhs.criterions)
            {
                lhs_conjunction.Add(criterion);
            }
            foreach (ICriterion criterion in rhs.criterions)
            {
                rhs_conjunction.Add(criterion);
            }
            combined.criterions.Add(Expression.Or(lhs_conjunction, rhs_conjunction));
            return(combined);
        }
Esempio n. 12
0
        protected override Junction SetupWhere(BlacklistQuery request)
        {
            var conjunction = new Conjunction();

            conjunction.Add(Restrictions.Where(() => RootAlias.InGameName == request.InGameName));
            return(conjunction);
        }
        protected override Expression VisitConditional(ConditionalExpression expr)
        {
            var visitorTrue = new SelectArgumentsVisitor(_rootCriteria, _session);

            visitorTrue.Visit(expr.IfTrue);

            var visitorFalse = new SelectArgumentsVisitor(_rootCriteria, _session);

            visitorFalse.Visit(expr.IfFalse);

            var visitorCondition = new WhereArgumentsVisitor(_rootCriteria, _session);

            visitorCondition.Visit(expr.Test);
            Conjunction conjunction = NHibernate.Criterion.Expression.Conjunction();

            foreach (var criterion in visitorCondition.CurrentCriterions)
            {
                conjunction.Add(criterion);
            }

            _projections.Add(
                NHibernate.Criterion.Projections
                .Conditional(conjunction,
                             visitorTrue.Projection,
                             visitorFalse.Projection)
                );

            return(expr);
        }
        public void SendBillSearchCriterionThatSearchesJustForASpecificBillId()
        {
            // Arrange
            const int expectedId = 2;
            Bill      bill       = new Bill {
                Id = expectedId, Date = "01.02.2017", KindOfBill = KindOfBill.Gutschrift
            };

            this._billEditViewModel.ChangeToLoadedMode(bill);

            Tuple <ICriterion, Expression <Func <Bill, Client> >, ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> criterion = null;

            Messenger.Default.Register <NotificationMessage <Tuple <ICriterion, Expression <Func <Bill, Client> >, ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> > >(this, x => criterion = x.Content);

            Conjunction billConjunction = Restrictions.Conjunction();

            billConjunction.Add(Restrictions.Where <Bill>(c => c.Id == expectedId));
            Tuple <ICriterion, Expression <Func <Bill, Client> >, ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> expectedTuple = new Tuple <ICriterion, Expression <Func <Bill, Client> >, ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion>(billConjunction, null, null, null, null);

            // Act
            this._billEditViewModel.SendBillSearchCriterionMessage();

            // Assert
            criterion.Should().NotBeNull();
            criterion.ToString().Should().Be(expectedTuple.ToString());
        }
Esempio n. 15
0
 public override void SetUp()
 {
     base.SetUp();
     _conjunction = Expression.Conjunction();
     _conjunction.Add(Expression.IsNull("Address"))
     .Add(Expression.Between("Count", 5, 10));
 }
Esempio n. 16
0
        private void BuildQueryFrom(Query query, ICriteria criteria)
        {
            IList <ICriterion> criterions = new List <ICriterion>();

            if (query.Criteria != null)
            {
                foreach (Criterion c in query.Criteria)
                {
                    //处理查询属性中还有.的情况,在这种情况下,表示查询条件并非本对象的直接属性,而是
                    //相关对象的属性,如使用包装所属产品的属性查询对应的包装时,则查询属性为package.Product.OriginalId="A0040"
                    int lastPositionOfDot = c.PropertyName.LastIndexOf(".");
                    if (lastPositionOfDot > 0)
                    {
                        TranslateCascadeToNHCriterion(c, criteria);
                    }
                    else
                    {
                        ICriterion criterion;
                        if (IndirectProperties.Contains(c.PropertyName.ToLower()))
                        {
                            criterion = GenerateSqlCriterion(c);
                        }
                        else
                        {
                            criterion = TranslateToNHCriterion(c);
                        }
                        criterions.Add(criterion);
                    }
                }

                if (query.QueryOperator == QueryOperator.And)
                {
                    Conjunction andSubQuery = Expression.Conjunction();
                    foreach (ICriterion criterion in criterions)
                    {
                        andSubQuery.Add(criterion);
                    }
                    criteria.Add(andSubQuery);
                }
                else
                {
                    Disjunction orSubQuery = Expression.Disjunction();
                    foreach (ICriterion criterion in criterions)
                    {
                        orSubQuery.Add(criterion);
                    }
                    criteria.Add(orSubQuery);
                }

                foreach (Query sub in query.SubQueries)
                {
                    BuildQueryFrom(sub, criteria);
                }
            }
        }
Esempio n. 17
0
        private static FieldBuilder GetOrAddValue <V>(TypeBuilder typeBuilder, Conjunction <V> conjunction, string symbol, Type fieldType, V value)
        {
            if (conjunction.TryGetValue(symbol, out var definedValue))
            {
                return(definedValue);
            }
            var field = typeBuilder.DefineField($"_f{NameCounter.GetCurrentCount()}", fieldType, FieldAttributes.Private | FieldAttributes.InitOnly);

            conjunction.Add(symbol, field, value);
            return(field);
        }
Esempio n. 18
0
        public ICriterion GetHeadwordRestrictions()
        {
            var conjunction = new Conjunction();

            foreach (var searchCriteriaQuery in m_conjunctionQuery.Where(x => x.CriteriaKey == CriteriaKey.Headword))
            {
                var disjunction = (Disjunction)searchCriteriaQuery.Restriction;
                conjunction.Add(disjunction);
            }

            return(conjunction);
        }
        private void BuildAnd(IJunction or, IEnumerator <QueryMember> members, IEnumerator values)
        {
            var and = new Conjunction();

            while (members.MoveNext())
            {
                var criterion = BuildCriterion(members.Current, values);
                and.Add(criterion);
            }

            or.Add(and);
        }
Esempio n. 20
0
        private static void BuildQueryFrom(Query query, ICriteria criteria)
        {
            IList <ICriterion> critrions = new List <ICriterion>();

            if (query.Criteria != null)
            {
                foreach (Criterion c in query.Criteria)
                {
                    ICriterion criterion;

                    switch (c.criteriaOperator)
                    {
                    case CriteriaOperator.Equal:
                        criterion = Expression.Eq(c.PropertyName, c.Value);
                        break;

                    case CriteriaOperator.LesserThanOrEqual:
                        criterion = Expression.Le(c.PropertyName, c.Value);
                        break;

                    default:
                        throw new ApplicationException("No operator defined");
                    }

                    critrions.Add(criterion);
                }

                if (query.QueryOperator == QueryOperator.And)
                {
                    Conjunction andSubQuery = Expression.Conjunction();
                    foreach (ICriterion criterion in critrions)
                    {
                        andSubQuery.Add(criterion);
                    }

                    criteria.Add(andSubQuery);
                }
                else
                {
                    Disjunction orSubQuery = Expression.Disjunction();
                    foreach (ICriterion criterion in critrions)
                    {
                        orSubQuery.Add(criterion);
                    }
                    criteria.Add(orSubQuery);
                }

                foreach (Query sub in query.SubQueries)
                {
                    BuildQueryFrom(sub, criteria);
                }
            }
        }
Esempio n. 21
0
        public IDictionary <string, IList <Entity_Student> > filteredStudentList(MyCriteria notifyCriteria)
        {
            Utility.logFile(Constant.METHOD_ENTER + Utility.getCurrentMethodName(1) + "(NotificationManagerImpl)", null, Constant.LOGTYPE_INFO);
            DetachedCriteria mainCriteria = DetachedCriteria.For <Entity_Student>("student");

            mainCriteria.CreateAlias("scoreObj", "score");
            Conjunction conjunction = Restrictions.Conjunction();

            conjunction.Add(Restrictions.Eq("student.myConfigObj.currentBatch", notifyCriteria.batch));
            conjunction.Add(Restrictions.Eq("student.myConfigObj.currentDegree", notifyCriteria.degree));
            conjunction.Add(Restrictions.Ge("score.X", notifyCriteria.X));
            conjunction.Add(Restrictions.Ge("score.cgpa", notifyCriteria.cgpa));
            conjunction.Add(Restrictions.Le("score.arrears", notifyCriteria.arrears));
            conjunction.Add(Restrictions.In("student.branch", notifyCriteria.branch));

            if (notifyCriteria.isDiplomaAllowed)
            {
                Disjunction disjunction = Restrictions.Disjunction();
                disjunction.Add(Restrictions.Ge("score.XII", notifyCriteria.XII));
                disjunction.Add(Restrictions.Ge("score. ", notifyCriteria.XII));

                conjunction.Add(disjunction);
            }
            else
            {
                conjunction.Add(Restrictions.Ge("score.XII", notifyCriteria.XII));
            }

            mainCriteria.Add(conjunction);

            if (!notifyCriteria.isPlaced)
            {
                DetachedCriteria subCriteria = DetachedCriteria.For <Entity_PlacementDetails>("placedObj");
                subCriteria.Add(Restrictions.EqProperty("placedObj.studentId", "student.studentId"));
                subCriteria.SetProjection(Projections.Distinct(Projections.Property("placedObj.studentId")));
                mainCriteria.Add(Subqueries.NotExists(subCriteria));
            }

            IList list = persistence.findByCriteria(mainCriteria);

            if (list != null && list.Count > 0)
            {
                IDictionary <string, IList <Entity_Student> > eligibleStudentMap = prepareStudentList(list.Cast <Entity_Student>().ToList());
                return(eligibleStudentMap);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 22
0
        public static IList <Airfield> FindSimilarAirfieldsByName(String value, String country)
        {
            ICriteria   cr = NHibernateHelper.GetCurrentSession().CreateCriteria(typeof(Airfield));
            Conjunction c  = new Conjunction();

            foreach (String s in value.Split(" ".ToCharArray()))
            {
                c.Add(Restrictions.Like("AirfieldName", s, MatchMode.Anywhere));
            }
            cr.Add(c);
            cr.Add(Restrictions.Eq("Country", country));
            return(cr.List <Airfield>());
        }
        public void SendBillSearchCriterionThatSearchesWithAllEnteredBillValues()
        {
            // Arrange
            Bill bill = ModelFactory.GetDefaultBill();

            this._billEditViewModel.ChangeToLoadedMode(bill);

            Tuple <ICriterion, Expression <Func <Bill, Client> >, ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> criterion = null;

            Messenger.Default.Register <NotificationMessage <Tuple <ICriterion, Expression <Func <Bill, Client> >, ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> > >(this, x => criterion = x.Content);

            Conjunction billConjunction = Restrictions.Conjunction();

            billConjunction.Add(Restrictions.Where <Bill>(c => c.KindOfBill == ModelFactory.DefaultBillKindOfBill));
            billConjunction.Add(Restrictions.Where <Bill>(c => c.KindOfVat == ModelFactory.DefaultBillKindOfVat));
            billConjunction.Add(Restrictions.Where <Bill>(c => c.Date.IsLike(ModelFactory.DefaultBillDate, MatchMode.Anywhere)));
            billConjunction.Add(Restrictions.Where <Bill>(c => c.Printed == ModelFactory.DefaultBillPrinted));

            Conjunction clientConjunction       = Restrictions.Conjunction();
            Conjunction cityToPostalConjunction = Restrictions.Conjunction();

            clientConjunction.Add(Restrictions.Where <Client>(c => c.Title == ModelFactory.DefaultClientTitle));
            clientConjunction.Add(Restrictions.Where <Client>(c => c.CompanyName.IsLike(ModelFactory.DefaultClientCompanyName, MatchMode.Anywhere)));
            clientConjunction.Add(Restrictions.Where <Client>(c => c.FirstName.IsLike(ModelFactory.DefaultClientFirstName, MatchMode.Anywhere)));
            clientConjunction.Add(Restrictions.Where <Client>(c => c.LastName.IsLike(ModelFactory.DefaultClientLastName, MatchMode.Anywhere)));
            clientConjunction.Add(Restrictions.Where <Client>(c => c.Street.IsLike(ModelFactory.DefaultClientStreet, MatchMode.Anywhere)));
            clientConjunction.Add(Restrictions.Where <Client>(c => c.HouseNumber.IsLike(ModelFactory.DefaultClientHouseNumber, MatchMode.Anywhere)));
            cityToPostalConjunction.Add(Restrictions.Where <CityToPostalCode>(c => c.PostalCode.IsLike(ModelFactory.DefaultCityToPostalCodePostalCode, MatchMode.Anywhere)));
            cityToPostalConjunction.Add(Restrictions.Where <CityToPostalCode>(c => c.City.IsLike(ModelFactory.DefaultCityToPostalCodeCity, MatchMode.Anywhere)));

            Tuple <ICriterion, Expression <Func <Bill, Client> >, ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> expectedTuple = new Tuple <ICriterion, Expression <Func <Bill, Client> >, ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion>(billConjunction, b => b.Client, clientConjunction, c => c.CityToPostalCode, cityToPostalConjunction);

            // Act
            this._billEditViewModel.SendBillSearchCriterionMessage();

            // Assert
            criterion.Should().NotBeNull();
            criterion.ToString().Should().Be(expectedTuple.ToString());
        }
Esempio n. 24
0
        private void VisitNotExpression(UnaryExpression expr)
        {
            var criterions = GetCriterion(rootCriteria, session, expr.Operand);

            Conjunction conjunction = Restrictions.Conjunction();

            foreach (var criterion in criterions)
            {
                conjunction.Add(criterion);
            }

            CurrentCriterions.Add(Restrictions.Not(conjunction));
        }
        public void SendBillSearchCriterionThatSearchesForBillsWithSpecificBillDataAndClientNumber()
        {
            // Arrange
            const int    expectedId = 2;
            KindOfBill   kindOfBill = KindOfBill.Gutschrift;
            const string date       = "01.02.2017";
            Client       client     = new Client()
            {
                Id = expectedId
            };
            Bill bill = new Bill {
                KindOfBill = kindOfBill, Date = date, Client = client
            };

            this._billEditViewModel.ChangeToLoadedMode(bill);

            Tuple <ICriterion, Expression <Func <Bill, Client> >, ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> criterion = null;

            Messenger.Default.Register <NotificationMessage <Tuple <ICriterion, Expression <Func <Bill, Client> >, ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> > >(this, x => criterion = x.Content);

            Conjunction billConjunction = Restrictions.Conjunction();

            billConjunction.Add(Restrictions.Where <Bill>(b => b.KindOfBill == kindOfBill));
            billConjunction.Add(Restrictions.Where <Bill>(b => b.Date.IsLike(date, MatchMode.Anywhere)));

            Conjunction clientConjunction = Restrictions.Conjunction();

            clientConjunction.Add(Restrictions.Where <Client>(c => c.Id == expectedId));

            Tuple <ICriterion, Expression <Func <Bill, Client> >, ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> expectedTuple = new Tuple <ICriterion, Expression <Func <Bill, Client> >, ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion>(billConjunction, b => b.Client, clientConjunction, null, null);

            // Act
            this._billEditViewModel.SendBillSearchCriterionMessage();

            // Assert
            criterion.Should().NotBeNull();
            criterion.ToString().Should().Be(expectedTuple.ToString());
        }
Esempio n. 26
0
        public static ICriterion IntersectCriterions(params ICriterion[] crits)
        {
            IList <ICriterion> list        = crits.ToList <ICriterion>();
            Conjunction        conjunction = new Conjunction();

            foreach (ICriterion criterion in list)
            {
                if (criterion != null)
                {
                    conjunction.Add(criterion);
                }
            }
            return(conjunction);
        }
Esempio n. 27
0
 /// <summary>
 /// Filtra por like con text y por condiciones booleanas
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="likeCriterias">criterias a los que aplicar el like</param>
 /// <param name="criteriaConditions">condicion booleana</param>
 /// <param name="text">texto para aplicar el like</param>
 /// <param name="count">cantidad de objetos a devolver</param>
 /// <returns></returns>
 public static List <T> GetByLikeAndConjunction <T>(List <Expression <Func <T, object> > > likeCriterias, Expression <Func <T, bool> > criteriaConditions, string text, int count)
     where T : class
 {
     try
     {
         NHibernateManager.GetInstance().Session.Clear();
         var disjunction = new Disjunction();
         var conjunction = new Conjunction();
         //Filtros para Likes
         foreach (var criteria in likeCriterias)
         {
             disjunction.Add(Restrictions.On(criteria).IsInsensitiveLike("%" + text + "%"));
         }
         //Se agrega otro criterio a la conjuncion
         conjunction.Add(criteriaConditions);
         conjunction.Add(disjunction);
         return(NHibernateManager.GetInstance().Session.QueryOver <T>().Where(conjunction).Take(count).List <T>().ToList());
     }
     catch (Exception ex)
     {
         throw (ex);
     }
 }
Esempio n. 28
0
        public void ThrowExceptionWhenClientCanNotBeGetByCriteriaBecauseDatabaseNotConnected()
        {
            // Arrange
            this.CreateRepository();

            Conjunction conjunction = Restrictions.Conjunction();

            conjunction.Add(Restrictions.Where <Client>(client => client.FirstName.IsLike("test")));

            // Act
            Action action = () => this._repository.GetByCriteria <Client>(conjunction, 1);

            // Assert
            action.ShouldThrow <NullReferenceException>();
        }
Esempio n. 29
0
        private void VisitAndAlsoExpression(BinaryExpression expr)
        {
            criterionStack.Push(new List <ICriterion>());
            Visit(expr.Left);
            Visit(expr.Right);
            var ands = criterionStack.Pop();

            var conjunction = new Conjunction();

            foreach (var crit in ands)
            {
                conjunction.Add(crit);
            }
            CurrentCriterions.Add(conjunction);
        }
Esempio n. 30
0
        public void SendClientSearchCriterionThatSearchesWithAllEnteredClientValues()
        {
            // Arrange
            this._clientEditViewModel.ChangeToLoadedMode(ModelFactory.GetDefaultClient());

            Tuple <ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> criterion = null;

            Messenger.Default.Register <NotificationMessage <Tuple <ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> > >(this, x => criterion = x.Content);

            Conjunction clientConjuction        = Restrictions.Conjunction();
            Conjunction cityToPostalConjunction = Restrictions.Conjunction();

            clientConjuction.Add(Restrictions.Where <Client>(c => c.Title == ModelFactory.DefaultClientTitle));
            clientConjuction.Add(Restrictions.Where <Client>(c => c.CompanyName.IsLike(ModelFactory.DefaultClientCompanyName, MatchMode.Anywhere)));
            clientConjuction.Add(Restrictions.Where <Client>(c => c.FirstName.IsLike(ModelFactory.DefaultClientFirstName, MatchMode.Anywhere)));
            clientConjuction.Add(Restrictions.Where <Client>(c => c.LastName.IsLike(ModelFactory.DefaultClientLastName, MatchMode.Anywhere)));
            clientConjuction.Add(Restrictions.Where <Client>(c => c.Street.IsLike(ModelFactory.DefaultClientStreet, MatchMode.Anywhere)));
            clientConjuction.Add(Restrictions.Where <Client>(c => c.HouseNumber.IsLike(ModelFactory.DefaultClientHouseNumber, MatchMode.Anywhere)));
            cityToPostalConjunction.Add(Restrictions.Where <CityToPostalCode>(c => c.PostalCode.IsLike(ModelFactory.DefaultCityToPostalCodePostalCode, MatchMode.Anywhere)));
            cityToPostalConjunction.Add(Restrictions.Where <CityToPostalCode>(c => c.City.IsLike(ModelFactory.DefaultCityToPostalCodeCity, MatchMode.Anywhere)));
            clientConjuction.Add(Restrictions.Where <Client>(c => c.DateOfBirth.IsLike(ModelFactory.DefaultClientDateOfBirth, MatchMode.Anywhere)));
            clientConjuction.Add(Restrictions.Where <Client>(c => c.PhoneNumber1.IsLike(ModelFactory.DefaultClientPhoneNumber1, MatchMode.Anywhere)));
            clientConjuction.Add(Restrictions.Where <Client>(c => c.PhoneNumber2.IsLike(ModelFactory.DefaultClientPhoneNumber2, MatchMode.Anywhere)));
            clientConjuction.Add(Restrictions.Where <Client>(c => c.MobileNumber.IsLike(ModelFactory.DefaultClientMobileNumber, MatchMode.Anywhere)));
            clientConjuction.Add(Restrictions.Where <Client>(c => c.Telefax.IsLike(ModelFactory.DefaultClientTelefax, MatchMode.Anywhere)));
            clientConjuction.Add(Restrictions.Where <Client>(c => c.Email.IsLike(ModelFactory.DefaultClientEmail, MatchMode.Anywhere)));

            Tuple <ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion> expectedTuple = new Tuple <ICriterion, Expression <Func <Client, CityToPostalCode> >, ICriterion>(clientConjuction, c => c.CityToPostalCode, cityToPostalConjunction);

            // Act
            this._clientEditViewModel.SendClientSearchCriterionMessage();

            // Assert
            criterion.Should().NotBeNull();
            criterion.ToString().Should().Be(expectedTuple.ToString());
        }
Esempio n. 31
0
        public void ThrowExceptionWhenBillCanNotBeGetByCriteriaBecauseDatabaseNotConnected()
        {
            // Arrange
            this.CreateRepository();

            Conjunction conjunction = Restrictions.Conjunction();

            conjunction.Add(Restrictions.Where <Bill>(bill => bill.Date.IsLike("23", MatchMode.Anywhere)));

            // Act
            Action action = () => this._repository.GetByCriteria <Bill>(conjunction, 1);

            // Assert
            action.ShouldThrow <NullReferenceException>();
        }