Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sean Dooley 289 posts 528 karma points
    Mar 07, 2012 @ 18:19
    Sean Dooley
    0

    Filtering nodes via Lambda Expressions assistance

    Trying to filtering various types of nodes depending on querystring parameters. The nodes can be filtered by the following

     

    • choosing a service filters the client and project nodes
    • choosing a client filters the project nodes

     

    The !service.IsEmpty() check works correctly, returning projects which contain the related service, and clients which the filtered projects contain.

    An issue occurs when selecting a client. When a service and a client is selected, it should only filter projects. Yet it is also filtering clients and returning only the selected client ... not want is needed. I can't work out what the issue might be.

    The "offending code" is below.

    Thanks in advance for any assistance, it is greatly appreciated.

     

    @{
        var service = Request["service"].IsEmpty() ? "" : Request["service"];
        var client = Request["client"].IsEmpty() ? "" : Request["client"];
        var clients = CurrentModel.Sibling("ClientSection").Descendants("Client").Items.Where(x => x.Visible);
        var services = CurrentModel.Sibling("ServiceSection").Descendants("Service").Items.Where(x => x.Visible);
        var projects = CurrentModel.Descendants("Project").Items.Where(x => x.Visible);
        if (!service.IsEmpty())
        {
            projects = projects.Where(p => p.GetPropertyValue("Service").Contains(service));
            clients = clients.Where(c => projects.Any(p => p.GetPropertyValue("Client").Contains(c.Id.ToString())));
        }
        if (!client.IsEmpty())
        {
            projects = projects.Where(p => p.GetPropertyValue("Client").Contains(client));
        }
    }

     

Please Sign in or register to post replies

Write your reply to:

Draft