public override IEnumerable List(FilterOptions filter)
        {
            IEnumerable list = null;
            var         documentTypeField = filter != null?filter.ExtractField("DocumentType") : null;

            if (documentTypeField != null)
            {
                filter.TraverseListPropertyName = "EntityId";
                var extEnum    = Enum.Parse(typeof(DocumentType), documentTypeField.Value);
                var extensions = this._fileManager.GetExtensions(extEnum.ToString());
                var culture    = StrixPlatform.CurrentCultureCode.ToLower();
                list = this.Manager.Query <Document>().Where(d => d.Culture.ToLower() == culture && d.IsCurrentVersion && extensions.Contains(d.File.Extension.ToLower())).Filter(filter).Map <DocumentListModel>();
                return(list);
            }
            else
            {
                list = base.List(filter);
            }

            foreach (var model in list.Cast <DocumentListModel>())
            {
                this.SetDocumentType(model);
            }

            return(list);
        }
 public void ExtractFieldShouldReturnTheFieldAndRemoveItFromTheFilter()
 {
     FilterOptions target = new FilterOptions();
     target.Filter.Filters.Add(new FilterField { Field = "Date", Operator = FilterFieldOperator.Equals, Value = DateTime.Now.ToString() });
     target.Filter.Filters.Add(new FilterField { Field = "Name", Operator = FilterFieldOperator.Contains, Value = "Test" });
     var actual = target.ExtractField("name");
     Assert.AreEqual("Test", actual.Value);
     Assert.AreEqual(1, target.Filter.Filters.Count);
 }
示例#3
0
        private IQueryable <User> FilterQuery(FilterOptions filter, IQueryable <User> query)
        {
            var nameField = filter.ExtractField("Name");

            if (nameField != null && !string.IsNullOrWhiteSpace(nameField.Value))
            {
                query = query.Where(q => q.Name.ToLower().Contains(nameField.Value.ToLower()));
            }

            var emailField = filter.ExtractField("Email");

            if (emailField != null && !string.IsNullOrWhiteSpace(emailField.Value))
            {
                query = query.Where(u => u.Email.ToLower().Contains(emailField.Value.ToLower()));
            }

            bool?approved             = null;
            var  accountApprovedField = filter.ExtractField("Approved");

            if (accountApprovedField != null && !string.IsNullOrWhiteSpace(accountApprovedField.Value))
            {
                approved = bool.Parse(accountApprovedField.Value);
            }

            bool?lockedOut      = null;
            var  lockedOutField = filter.ExtractField("LockedOut");

            if (lockedOutField != null && !string.IsNullOrWhiteSpace(lockedOutField.Value))
            {
                lockedOut = bool.Parse(lockedOutField.Value);
            }

            if (approved.HasValue || lockedOut.HasValue)
            {
                query = query.Join(this._dataSource.Query <UserSecurity>(), u => u.Id, s => s.Id, (u, s) => new { User = u, Security = s })
                        .Where(u => (approved == null || u.Security.Approved == approved.Value) && (lockedOut == null || u.Security.LockedOut == lockedOut.Value)).Select(u => u.User);
            }

            return(query);
        }