Question

I've set up two Dynamic Content Modules and successfully linked one to the other in the backend. The problem I am having is that I am trying to query the values of one from the other. The example is as follows:

Module One: Business Area -> Business Unit

Module Two: Services

So Business Unit has an Array of Guid related to Services. I've created a Widget where you can click on the service and it would load the service information, but now I want to show all the business units in the service. I've had to do it this way because I'll be displaying all Units in an Area as well and suspect they may have a Unit in multiple service areas knowing how users like to change things :)

So are there any suggestions on how I can retrieve these? I thought I would start with the Page Guid but what I really want is the Guid of the Service that was passed to the page and then to be able to run a Linq query using that. What I've got so far throws an error of:

Database mapped field uses different type 'System.Guid[]'.
Parameter name: methodCallExpression
Actual value was re-d.FieldValue("Service").

Which was generated from

var pManager = Telerik.Sitefinity.Modules.Pages.PageManager.GetManager();
Telerik.Sitefinity.Pages.Model.PageData page = pManager.GetPageData(new Guid(currentNode.Key));

if (page != null)
{
    var serviceGuid = new Guid(SiteMapBase.GetCurrentProvider().CurrentNode.Key);

    var list = new List<Guid>();
    list.Add(serviceGuid);
    Guid[] guidList = list.ToArray();

    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
    Type serviceType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Services.Service");
    Type businessUnitType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.BusinessAreas.BusinessUnit");

    myFilteredCollection = dynamicModuleManager.GetDataItems(businessUnitType)
                                               .Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Visible == true)
                                               .Where(d => d.GetValue<TrackedList<Guid>>("Service").Contains(guidList))
                                               .OrderBy(i => i.GetValue<System.Decimal>("SortOrder"));                
    }

Would love any hints as to where I should be looking. I feel like I've hit the point of reading the same five posts and blogs continuously.

Was it helpful?

Solution

I've created a Business Area module in module builder with Business Units as a child type. I've also created a Services module in module builder and created a dynamic items field control selector for it. On the Business Unit module, I've added a Guid[] field and am using the Services selector to associated services.

I've set up a couple pages in Sitefinity, a page with a Services list widget on it and another page that has a Services details widget on it, the list points to the details page. On the Services details widget template, I'm including a custom control that uses the below code to look up the Service via the url name, then it looks up the Business Units and checks if any of them are associated to the Service.

protected void Page_Load(object sender, EventArgs e)
{
    RouteHelper.SetUrlParametersResolved();

    string urlParams = this.GetUrlParameterString(true);

    if (!string.IsNullOrEmpty(urlParams))
    {
        urlParams = urlParams.Replace("/", string.Empty);


        var dynamicModuleManager = DynamicModuleManager.GetManager(string.Empty);
        var serviceType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Services.Service");
        var service = dynamicModuleManager.GetDataItems(serviceType).FirstOrDefault(s => s.Status == ContentLifecycleStatus.Live && s.UrlName == urlParams);

        if (service != null)
        {
            var businessUnits = GetBusinessUnits().Where(bu => bu.GetValue<Guid[]>("Services").Contains(service.OriginalContentId));

            foreach (var bu in businessUnits)
            {
                //do something cool
            }
        }
    }
}

public IQueryable<DynamicContent>GetBusinessUnits()
{
    var providerName = String.Empty;
    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
    Type businessUnitType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.BusinessAreas.BusinessUnit");

    var myCollection = dynamicModuleManager.GetDataItems(businessUnitType).Where(bu => bu.Status == ContentLifecycleStatus.Live);

    return myCollection;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top