Entity Relationship management

Aug 19, 2014 at 9:56 PM
Edited Aug 20, 2014 at 4:59 AM

Aug 21, 2014 at 1:12 PM
Hi MartyNZ

You're right - the downloadable demos are missing. I'll try to get some out in a few days - you can use the "look-inside" feature on (here)[http://2sexycontent.org/dnn-app-demos/Apps/FAQ-with-Categories] in the meantime. Also look at the sub-pages.
Aug 22, 2014 at 4:06 PM
Hi MartyNZ

We finally got around to creating extensive examples for this. I made 6 views doing different kinds of filtering and packaged them into the FAQ with Categories App.

Would love to hear your feedback, and/or if you see the need for other examples.
Marked as answer by 2sicDev on 8/22/2014 at 8:15 AM
Aug 25, 2014 at 11:58 PM
Hi Again,
I've taken a look at the above and it's a great help.
I just need one more nudge in the right direction.
I've modified your code as such:
@using ToSic.SexyContent
// variable which will contain the sorted categories
IEnumerable<dynamic> sortedCategories;

// Prepare the data - get all categories through the pipeline
public override void CustomizeData()
    // get all categories of these questions, then get the distinct entities 
    // this could all be done on 1 line, but it would be harder for people who don't know LINQ yet
    var vProducts = AsDynamic(Data["Default"].List);
    var categoriesUsed = vProducts.SelectMany(q => ((List<DynamicEntity>)q.Product_Category));
    var distinctCategories = categoriesUsed.Select(AsEntity).Distinct();    // Distinct only works reliably when cast as entity
    sortedCategories = AsDynamic(distinctCategories).OrderBy(q => q.EntityId);
<ol> @foreach (var c in sortedCategories) { <li>@c.Category</li> <ul> @foreach (var q in AsDynamic(Data["Default"].List)) { <li class="sc-element faq-set" data-tags="@String.Join(",", ((List<DynamicEntity>)q.Product_Category).Select(a => AsDynamic(a).EntityId))"> @q.Toolbar <a class="faq-question" style="cursor: pointer"> @q.Product_Name </a> <div class="faq-answer" style="display: none">@Html.Raw(q.Product_Description)</div> </li> } </ul> } </ol> ===================================================
Which now creates an ordered list of categories with a nested unordered list of items within each category.
What is NOT happening is that my items list is not getting filtered to only show the items relevant to the particular category as below:

  1. Savoury Pies
  2. Mince
  3. Cherry
  4. 1. HTC
  5. 1. Mince & Cheese
  6. 1. Sheffield Supreme
  7. Fruit Pies
  8. Mince
  9. Cherry
  10. HTC
  11. Mince & Cheese
  12. Sheffield Supreme
  13. Gourmet Pies... etc. you get the idea
Could some-one please explain how to modify my code above to get the desired filtering


P.S. I'm sure you've guessed by now my programming skills are virtually non-existent.
Aug 26, 2014 at 7:09 AM
Hi MartyNZ - does that mean New Zealand?

if you look at (this demo)[http://2sexycontent.org/dnn-app-demos/Apps/FAQ-with-Categories/FAQ-with-Category-and-List-Module] you'll see the second module's source has a function block as follows:
    // Prepare the data - get all categories through the pipeline
    public override void CustomizeData()
        // new features in 6.1 - the App DataSource CreateSource<App> and also the RelationshipFilter
        // Just add the items which have the relationship to the category in the URL
        var qsOfCat = CreateSource<RelationshipFilter>(App.Data["QandA"]);
        qsOfCat.Relationship = "Categories";
        qsOfCat.Filter = "[QueryString:Category||" + (Content.Category.Count > 0 ? Content.Category[0].Name : "") + "]";
        Data.In.Add("QandA", qsOfCat["Default"]);
This code is also included in the app, it's the 2nd part of the 2-part view (one categories, one the resulting filtered questions).

This one is applying the Relationship filter - based on the URL and if it can't find a URL, it takes the value that was set in the view by the admin

You started off with another example - one which doesn't use a relationship filter. You can extend it now - just tweak around a bit OR start over with the "Part 2" view.

Aug 26, 2014 at 12:25 PM
HI Daniel, Thanks for your response, and yes, it means New Zealand (Christchurch to be precise)
Re: the code snippet above. Am I right in thinking that in my case I have to apply the filter to the inner foreach loop? And your code uses the querystring to filter on, how would I do that using a named anchor in the url?

The goal here is to take the list as shown above and display it using the DNN Tab Interface. So that I can have tabs for each category with filtered list items within each tab.

Aug 28, 2014 at 9:33 AM
Hi MartyNZ

I think you're asking the wrong question. I believe you don't want to filter, but you want to group the data into the tabs. Of course you could also apply a filter for each tab, but that would be rathercumbersome.
In case I'm right - don't filter, but do some research on LINQ Grouping

here some approximate code, but I didn't test it, so it's probably wrong - just as an idea how to start...
foreach(var group in AsDynamic(Data["Default"]).GroupBy(x => x.Group)
  <div class="tab">
     @foreach(var item in group)
Aug 28, 2014 at 12:23 PM
I think you're right. I will follow that up and check out LINQ Grouping.