예제 #1
0
        private IEnumerable <Classroom> GetByCriteria(
            Guid addressOid,
            IEnumerable <string> equipmentElements,
            SeatingType?seating = default(SeatingType?),
            int?capacity        = default(int?))
        {
            var criteria = new CriteriaOperatorCollection();

            if (addressOid != Guid.Empty)
            {
                criteria.Add(
                    new BinaryOperator("Address", addressOid, BinaryOperatorType.Equal)
                    );
            }

            if (equipmentElements?.Any() ?? false)
            {
                criteria.Add(CriteriaOperator.Or(
                                 equipmentElements.Select(e => new BinaryOperator(
                                                              "AdditionalInfo",
                                                              $"%{e}%",
                                                              BinaryOperatorType.Like
                                                              ))
                                 ));
            }

            if (capacity.HasValue)
            {
                criteria.Add(
                    new BinaryOperator(
                        "Capacity",
                        capacity.Value,
                        BinaryOperatorType.GreaterOrEqual
                        )
                    );
            }

            if (seating.HasValue)
            {
                criteria.Add(new BinaryOperator("SeatingType", seating.Value));
            }

            return(criteria.Any() ?
                   new XPCollection <Classroom>(session, CriteriaOperator.And(criteria)) :
                   new XPCollection <Classroom>(session));
        }