More in this section
Forums / Module Builder / Matching content selected Id to database list of items

Matching content selected Id to database list of items

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 1 answered
  1. Hooman
    Hooman avatar
    19 posts
    Registered:
    24 Jun 2016
    19 Jul 2016
    Link to this post

    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 that 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

  2. Hooman
    Hooman avatar
    19 posts
    Registered:
    24 Jun 2016
    19 Jul 2016
    Link to this post

    Instead of getting a list of itemviewmodel first, 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));

     

    Ps: Apparently the dynamic selector returns the Id of the master version of the content which I did not understand initially what Id it was returning. 

    Answered
2 posts, 1 answered