예제 #1
0
        public List <TextContentObject> FindAll(string query)
        {
            var all = _findAll(query);
            List <TextContentObject> result = new List <TextContentObject>();

            foreach (var item in all)
            {
                var txtObj = new TextContentObject(item, this.context);
                result.Add(txtObj);
            }
            return(result.OrderByDescending(o => o.TextContent.LastModified).ToList());
        }
예제 #2
0
        public List <TextContentObject> All()
        {
            List <TextContentObject> result = new List <TextContentObject>();

            var allcontents = this.context.WebSite.SiteDb().TextContent.All();

            foreach (var item in allcontents)
            {
                TextContentObject model = new TextContentObject(item, this.context);
                result.Add(model);
            }
            return(result);
        }
예제 #3
0
        public List <TextContentObject> take(int count)
        {
            var sitedb = this.txtObjRepo.context.WebSite.SiteDb();

            var allContentTypes = sitedb.ContentTypes.All();

            ContentType   onlyType   = null;
            ContentFolder onlyFolder = null;

            var condition = this.txtObjRepo.ParseCondition(this.SearchCondition);

            var tablequery = sitedb.TextContent.Query.Where(o => o.Online == true);

            if (condition.FolderId != default(Guid))
            {
                tablequery.Where(o => o.FolderId == condition.FolderId);

                var folder = sitedb.ContentFolders.Get(condition.FolderId);
                if (folder != null)
                {
                    onlyFolder = folder;
                    onlyType   = sitedb.ContentTypes.Get(folder.ContentTypeId);
                }
            }

            if (condition.ContentTypeId != default(Guid))
            {
                tablequery.Where(o => o.ContentTypeId == condition.ContentTypeId);
                var type = sitedb.ContentTypes.Get(condition.ContentTypeId);
                if (type != null)
                {
                    onlyType = type;
                }
            }


            if (condition.CategoryId != default(Guid))
            {
                var allcontentids = sitedb.ContentCategories.Query.Where(o => o.CategoryId == condition.CategoryId).SelectAll().Select(o => o.ContentId).ToList();

                tablequery.WhereIn("Id", allcontentids);
            }

            var all = tablequery.SelectAll();


            var filteritems = this.txtObjRepo.filterItems(all, condition.Conditions, onlyType, onlyFolder);

            if (filteritems == null || !filteritems.Any())
            {
                return(new List <TextContentObject>());
            }


            if (!string.IsNullOrWhiteSpace(this.OrderByField))
            {
                ContentProperty prop = null;
                if (onlyType != null)
                {
                    prop = onlyType.Properties.Find(o => Lib.Helper.StringHelper.IsSameValue(o.Name, this.OrderByField));
                }

                if (prop == null)
                {
                    var uniqueC = filteritems
                                  .Select(p => p.ContentTypeId)
                                  .Distinct();

                    foreach (var item in uniqueC)
                    {
                        var uniquetype = sitedb.ContentTypes.Get(item);
                        if (uniquetype != null)
                        {
                            var find = uniquetype.Properties.Find(o => Lib.Helper.StringHelper.IsSameValue(o.Name, this.OrderByField));
                            if (find != null)
                            {
                                prop = find;
                                break;
                            }
                        }
                    }
                }

                if (prop != null)
                {
                    if (this.Ascending)
                    {
                        filteritems = filteritems.OrderBy(o => GetValue(o.GetValue(this.OrderByField), prop.DataType)).ToList();
                    }
                    else
                    {
                        filteritems = filteritems.OrderByDescending(c => GetValue(c.GetValue(OrderByField), prop.DataType)).ToList();
                    }
                }
            }


            var txtResult = filteritems.Skip(this.skipcount).Take(count);

            List <TextContentObject> result = new List <TextContentObject>();

            foreach (var item in txtResult)
            {
                var obj = new TextContentObject(item, this.txtObjRepo.context);
                result.Add(obj);
            }
            return(result);
        }