Copied to clipboard

Flag this post as spam?

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


  • Carlos 338 posts 472 karma points
    Sep 02, 2014 @ 17:40
    Carlos
    0

    How do you use uComponents User Picker, get value AND check if it is not null?

    How do you use uComponents User Picker, get value AND check if it is not null?

     

    Umbraco 4.11.10, uComponents 5.0

    We ran into an issue with our uComponents User Picker datatype where it looks like it is breaking the Macro or not rendering it.

    We are using the uComponents user picker for a block of our nodes.  We want to check to see if the node 

    1. Has the property with the User Picker Datatype (Alternate Author)

    2. If the property is not null.  

    We wrote some code that was working, but we then had some orphaned nodes someplace and had to reinstantiate the User Picker Datatype on those nodes.  Some of the nodes may not have a user selected. This is why we want to check to see if the node has the property AND if it is not null.  The User picker uses PreValues so getting those is an issue too.

    Here is the code we currently have, but it does not meet our needs currently as described above. We are using some Lamda, but this may need some tweaking

    Help writing the correct code is much apprecaited.

     

    @using umbraco
    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNode
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.NodeFactory
    
    
    
    @*@using DWTBlog;*@
    
    @{
    
       var baseNode = @Model.AncestorOrSelf("DWTBlogLanding");
    
    
      var newNode = uQuery.GetRootNode().GetDescendantNodes().Where(x => x.HasProperty("alternateAuthor") && x.NodeTypeAlias == "ScienceResearchUpdatesPost").OrderBy(x => umbraco.BusinessLogic.User.GetUser(x.GetProperty("alternateAuthor")).Name);
    
    
        @*
    DynamicNode contentRoot = new DynamicNode(-1);
    *@
    
      string altAuthorList = "";
    
      

    Authors

      @foreach(var node in newNode) {
    • @node.CreatorName
    • var user = umbraco.BusinessLogic.User.GetUser(node.GetProperty("alternateAuthor")); @* if (altAuthorList != user.Name) { var numOfPosts = NumberOfBlogsByAlternateAuthor(newNode, node.GetProperty("alternateAuthor")); if (numOfPosts > 0) { if(user.Name == "Administrator" || @node.CreatorName == "Administrator"){ } else{
    • @user.Name (@numOfPosts)
    • } } else {
    • @node.CreatorName (@numOfPosts)
    • } }*@ altAuthorList = user.Name; }
    } @functions{ @* public static int NumberOfBlogsByAlternateAuthor(IEnumerable nodes, int alternateAuthorId) { var nodeList = new List(); foreach (var node in nodes) { if (node.GetProperty("alternateAuthor") == alternateAuthorId) { nodeList.Add(node); } } return nodeList.Count; }*@ public static IEnumerable GetListOfNodes(IEnumerable nodes, string category) { var myNodeList = new List(); foreach (var node in nodes) { var myCategories = node.GetProperty("dwtBlogCategories").Value; if (!String.IsNullOrWhiteSpace(myCategories)) { var myCategoryList = new List(myCategories.Split(',')); if (myCategoryList.Any(x => x == category)) { myNodeList.Add(node); } } } return myNodeList; } }

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft