sitefinitysitefinity-feather

Matching selecting dynamic content Id to list of ItemViewModel in SiteFinity


I have created a module Products and content type product. I am creating a custom widget to display a single product. I have setup my designer and once I drop the widget on a page I can select from the product list using the sf-list-selector sf-dynamic-items-selector. My issue is matching the selected item ID to the list of products my widget is pulling up. Here is the code the widget uses to retrieve all products:

var dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
var contentType = TypeResolutionService.ResolveType(typeName);
var contentElements = dynamicModuleManager.GetDataItems(contentType).Where(x => x.Status == ContentLifecycleStatus.Live);

products = contentElements.ToArray().Select(p => new ItemViewModel(p)).ToArray();

This works good and pulls up the list of products. The question is how to filter this list using the selected product id from the designer. I have this and they don't match:

products.Single(p => p.DataItem.Id == Guid.Parse(selectedProductId))

How do I go from the ItemViewModel to the Id the selector is giving me?

using Feather 9.1


Solution

  • Went a different route. Instead of getting a list and filtering did so:

    var dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
    var contentType = TypeResolutionService.ResolveType(typeName);
    var contentElement = dynamicModuleManager.GetDataItem(contentType, Guid.Parse(selectedProductId));
    product =  new ItemViewModel(dynamicModuleManager.Lifecycle.GetLive(contentElement));