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.
}
@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;
}
}
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.
@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; } }is working on a reply...