Much better query to find allowable containers.

--HG--
branch : dev
This commit is contained in:
Dave Reed
2011-03-10 18:22:41 -08:00
parent b8ab611aa9
commit 823ddd08b3

View File

@@ -42,13 +42,9 @@ namespace Orchard.Core.Containers.Drivers {
commonPart.Container = _contentManager.Get(model.ContainerId, VersionOptions.Latest); commonPart.Container = _contentManager.Get(model.ContainerId, VersionOptions.Latest);
} }
// these containers are allowed to contain any content type // note: string.isnullorempty not being recognized by linq-to-nhibernate hence the inline or
var freeContainers = _contentManager.Query<ContainerPart, ContainerPartRecord>(VersionOptions.Latest).Where(ctr => ctr.ItemContentType == null).List(); var containers = _contentManager.Query<ContainerPart, ContainerPartRecord>(VersionOptions.Latest)
// these containers are allowed to contain any content type (workaround: string.IsNullOrEmpty not functioning) .Where(ctr => ctr.ItemContentType == null || ctr.ItemContentType == "" || ctr.ItemContentType == part.ContentItem.ContentType).List();
var freeContainers2 = _contentManager.Query<ContainerPart, ContainerPartRecord>(VersionOptions.Latest).Where(ctr => ctr.ItemContentType == "").List();
// these containers are restricted to contain the content type of this content item
var restrictedContainers = _contentManager.Query<ContainerPart, ContainerPartRecord>(VersionOptions.Latest).Where(ctr => ctr.ItemContentType == part.ContentItem.ContentType).List();
var containers = restrictedContainers.Concat(freeContainers).Concat(freeContainers2).OrderByDescending(ctr => ctr.As<CommonPart>().PublishedUtc);
var listItems = new[] { new SelectListItem { Text = T("(None)").Text, Value = "0" } } var listItems = new[] { new SelectListItem { Text = T("(None)").Text, Value = "0" } }
.Concat(containers.Select(x => new SelectListItem { .Concat(containers.Select(x => new SelectListItem {