public virtual ActionResult Selectable(string categoryFolder, int?page, int?pageSize, string orderField = null, string direction = null) { var textFolder = (TextFolder)(FolderHelper.Parse <TextFolder>(Repository, categoryFolder).AsActual()); Schema schema = new Schema(Repository, textFolder.SchemaName).AsActual(); SchemaPath schemaPath = new SchemaPath(schema); ViewData["Folder"] = textFolder; ViewData["Schema"] = schema; ViewData["Template"] = textFolder.GetFormTemplate(FormType.Selectable); IContentQuery <TextContent> query = textFolder.CreateQuery(); if (string.IsNullOrEmpty(orderField)) { query = query.DefaultOrder(); } else { if (!string.IsNullOrEmpty(direction) && direction.ToLower() == "asc") { query = query.OrderBy(orderField); } else { query = query.OrderByDescending(orderField); } } return(View(query.ToPageList(page ?? 1, pageSize ?? textFolder.PageSize))); }
public static IContentQuery <T> OrderBy <T>(this IContentQuery <T> query, string partAndProperty, bool descendingOrder) where T : IContent { //todo: (heskew) order by custom part properties switch (partAndProperty) { case "ContainablePart.Weight": query = descendingOrder ? query.OrderByDescending <ContainablePartRecord>(record => record.Position) : query.OrderBy <ContainablePartRecord>(record => record.Position); break; case "TitlePart.Title": query = descendingOrder ? query.OrderByDescending <TitlePartRecord>(record => record.Title) : query.OrderBy <TitlePartRecord>(record => record.Title); break; case "CustomPropertiesPart.CustomOne": query = descendingOrder ? query.OrderByDescending <CustomPropertiesPartRecord>(record => record.CustomOne) : query.OrderBy <CustomPropertiesPartRecord>(record => record.CustomOne); break; case "CustomPropertiesPart.CustomTwo": query = descendingOrder ? query.OrderByDescending <CustomPropertiesPartRecord>(record => record.CustomTwo) : query.OrderBy <CustomPropertiesPartRecord>(record => record.CustomTwo); break; case "CustomPropertiesPart.CustomThree": query = descendingOrder ? query.OrderByDescending <CustomPropertiesPartRecord>(record => record.CustomThree) : query.OrderBy <CustomPropertiesPartRecord>(record => record.CustomThree); break; case "CommonPart.CreatedUtc": query = descendingOrder ? query.OrderByDescending <CommonPartRecord>(record => record.CreatedUtc) : query.OrderBy <CommonPartRecord>(record => record.CreatedUtc); break; default: // "CommonPart.PublishedUtc" query = descendingOrder ? query.OrderByDescending <CommonPartRecord>(record => record.PublishedUtc) : query.OrderBy <CommonPartRecord>(record => record.PublishedUtc); break; } return(query); }
public static IContentQuery <T> SortBy <T>(this IContentQuery <T> list, string sortField, string sortDir) where T : ContentBase { if (!string.IsNullOrEmpty(sortField)) { var sort = sortField; if (sortDir == "desc") { return(list.OrderByDescending(sortField)); } else { return(list.OrderBy(sortField)); } } return(list); }
public ActionResult Index(PagerParameters pagerParameters) { Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); IContentQuery <ContactPart, ContactPartRecord> contacts = _contactService.GetContacts(); var pagerShape = Shape.Pager(pager).TotalItemCount(contacts.Count()); var contactRequests = contacts .OrderByDescending <ContactPartRecord, DateTime?>(cpr => cpr.ContactDateUtc) .Slice(pager.GetStartIndex(), pager.PageSize) .ToList(); // TODO: see if we need to return something other than the raw contact items here var model = new ContactRequestListViewModel { ContactRequests = contactRequests, Pager = pagerShape }; return(View(model)); }
private static IContentQuery <TextContent> SortByField(string sortField, string sortDir, IContentQuery <TextContent> query) { if (string.IsNullOrEmpty(sortField)) { query = query.DefaultOrder(); } else { if (!string.IsNullOrEmpty(sortDir) && sortDir.ToLower() == "desc") { query = query.OrderByDescending(sortField); } else { query = query.OrderBy(sortField); } } return(query); }
public static IContentQuery <TextContent> DefaultOrder(this IContentQuery <TextContent> textContents, string orderField, OrderDirection orderDirection = OrderDirection.Descending) { if (textContents is TextContentQueryBase) { var textFolder = ((TextContentQueryBase)textContents).Folder.AsActual(); if (textFolder.Sortable.HasValue && textFolder.Sortable.Value) { orderField = "Sequence"; orderDirection = OrderDirection.Descending; } if (orderDirection == OrderDirection.Ascending) { return(textContents.OrderBy(orderField)); } else { return(textContents.OrderByDescending(orderField)); } } return(textContents); }
public static IContentQuery <TextContent> DefaultOrder(this IContentQuery <TextContent> contentQuery) { if (contentQuery is TextContentQueryBase) { var textFolder = ((TextContentQueryBase)contentQuery).Folder.AsActual(); var orderField = "UtcCreationDate"; var direction = OrderDirection.Descending; if (textFolder.OrderSetting != null && !string.IsNullOrEmpty(textFolder.OrderSetting.FieldName)) { orderField = textFolder.OrderSetting.FieldName; direction = textFolder.OrderSetting.Direction; } if (direction == OrderDirection.Ascending) { return(contentQuery.OrderBy(orderField)); } else { return(contentQuery.OrderByDescending(orderField)); } } return(contentQuery); }
public static IContentQuery <TextContent> DefaultOrder(this IContentQuery <TextContent> contentQuery) { if (contentQuery is TextContentQueryBase) { var textFolder = ((TextContentQueryBase)contentQuery).Folder.AsActual(); var orderField = "UtcCreationDate"; var direction = OrderDirection.Descending; if (textFolder.Sortable.HasValue && textFolder.Sortable.Value == true) { orderField = "Sequence"; direction = OrderDirection.Descending; } if (direction == OrderDirection.Ascending) { return(contentQuery.OrderBy(orderField)); } else { return(contentQuery.OrderByDescending(orderField)); } } return(contentQuery); }
public static IContentQuery <TextContent> DefaultOrder(this IContentQuery <TextContent> textContents, TextFolder textFolder) { if (textContents is TextContentQueryBase) { string orderField = SystemFieldNames.UtcCreationDate; OrderDirection orderDirection = OrderDirection.Descending; if (textFolder.Sortable.HasValue && textFolder.Sortable.Value) { orderField = "Sequence"; orderDirection = OrderDirection.Descending; } if (orderDirection == OrderDirection.Ascending) { return(textContents.OrderBy(orderField)); } else { return(textContents.OrderByDescending(orderField)); } } return(textContents); }
private static IContentQuery<TextContent> SortByField(string sortField, string sortDir, IContentQuery<TextContent> query) { if (string.IsNullOrEmpty(sortField)) { query = query.DefaultOrder(); } else { if (!string.IsNullOrEmpty(sortDir) && sortDir.ToLower() == "desc") { query = query.OrderByDescending(sortField); } else { query = query.OrderBy(sortField); } } return query; }
public virtual ActionResult Index(string folderName, string parentUUID, string parentFolder, string search , IEnumerable <WhereClause> whereClause, int?page, int?pageSize, string orderField = null, string direction = null) { //compatible with the Folder parameter changed to FolderName. folderName = folderName ?? this.ControllerContext.RequestContext.GetRequestValue("Folder"); TextFolder textFolder = new TextFolder(Repository, folderName).AsActual(); var schema = textFolder.GetSchema().AsActual(); SchemaPath schemaPath = new SchemaPath(schema); ViewData["Folder"] = textFolder; ViewData["Schema"] = schema; ViewData["Template"] = textFolder.GetFormTemplate(FormType.Grid); ViewData["WhereClause"] = whereClause; SetPermissionData(textFolder); IEnumerable <TextFolder> childFolders = new TextFolder[0]; //Skip the child folders on the embedded folder grid. if (string.IsNullOrEmpty(parentFolder)) { if (!page.HasValue || page.Value <= 1) { childFolders = ServiceFactory.TextFolderManager.ChildFolders(textFolder, search).Select(it => it.AsActual()); } } IContentQuery <TextContent> query = textFolder.CreateQuery(); if (string.IsNullOrEmpty(orderField)) { query = query.DefaultOrder(); } else { if (!string.IsNullOrEmpty(direction) && direction.ToLower() == "desc") { query = query.OrderByDescending(orderField); } else { query = query.OrderBy(orderField); } } bool showTreeStyle = schema.IsTreeStyle; //如果有带搜索条件,则不输出树形结构 if (!string.IsNullOrEmpty(search)) { IWhereExpression exp = new FalseExpression(); foreach (var item in schema.Columns.Where(it => it.ShowInGrid)) { exp = new OrElseExpression(exp, (new WhereContainsExpression(null, item.Name, search))); } if (exp != null) { query = query.Where(exp); } showTreeStyle = false; } if (whereClause != null && whereClause.Count() > 0) { var expression = WhereClauseToContentQueryHelper.Parse(whereClause, schema, new MVCValueProviderWrapper(ValueProvider)); query = query.Where(expression); showTreeStyle = false; } if (!string.IsNullOrWhiteSpace(parentUUID)) { query = query.WhereEquals("ParentUUID", parentUUID); } else { //有两种情况需要考虑要不要查询所有的数据(ParentUUID=null) //1.树形结构数据,第一次查询需要过滤ParentUUID==null //2.自嵌套的目前结构,也需要过滤ParentUUID==null var selfEmbedded = textFolder.EmbeddedFolders != null && textFolder.EmbeddedFolders.Contains(textFolder.FullName, StringComparer.OrdinalIgnoreCase); if (showTreeStyle || selfEmbedded) { query = query.Where(new OrElseExpression(new WhereEqualsExpression(null, "ParentUUID", null), new WhereEqualsExpression(null, "ParentUUID", ""))); } } if (childFolders != null) { childFolders = childFolders .Select(it => it.AsActual()) .Where(it => it.VisibleOnSidebarMenu == null || it.VisibleOnSidebarMenu.Value == true) .Where(it => Kooboo.CMS.Content.Services.ServiceFactory.WorkflowManager.AvailableViewContent(it, User.Identity.Name)); } page = page ?? 1; pageSize = pageSize ?? textFolder.PageSize; //var pagedList = query.ToPageList(page.Value, pageSize.Value); //IEnumerable<TextContent> contents = pagedList.ToArray(); //if (Repository.EnableWorkflow == true) //{ // contents = ServiceFactory.WorkflowManager.GetPendWorkflowItemForContents(Repository, contents.ToArray(), User.Identity.Name); //} //var workflowContentPagedList = new PagedList<TextContent>(contents, page.Value, pageSize.Value, pagedList.TotalItemCount); //ViewData["ContentPagedList"] = workflowContentPagedList; return(View(new TextContentGrid() { ChildFolders = childFolders.ToArray(), ContentQuery = query, PageIndex = page.Value, PageSize = pageSize.Value, ShowTreeStyle = showTreeStyle })); }