I need to sort my backend items in alphabetical where published item is at the bottom and the unpublished at top, but Im doing something wrong I don't know the type I have to use, I tried IContent and Document, they get sorted but it seams like they get duplicated also ?, I guess that's because Im making a new item in the database by saving the node again after changing the sortnr.
int sortNr = 0;
// unpublished
var contentService = ApplicationContext.Current.Services.ContentService;
List<Umbraco.Core.Models.IContent> unpublished = contentService.GetChildren(parentNodeToSortedItems.Id).Where(x => !x.Published).OrderBy(x => x.Name).ToList();
// published
List<Document> publishedItems = new List<Document>();
List<umbraco.interfaces.INode> published = parentNodeToSortedItems.ChildrenAsList.OrderBy(x => x.Name).ToList();
foreach (var item in published )
{
Document document = new Document(item.Id);
publishedItems.Add(document);
}
for (int i = 0; i < unpublished.Count; i++)
{
unpublished[i].SortOrder = i;
contentService.Save(unpublished[i]);
sortNr++;
}
for (int i = 0; i < p.Count; i++)
{
p[i].sortOrder = sortNr;
p[i].SaveAndPublish(new umbraco.BusinessLogic.User(0));
sortNr++;
}
Sort notes in backend in alphabetical
I need to sort my backend items in alphabetical where published item is at the bottom and the unpublished at top, but Im doing something wrong I don't know the type I have to use, I tried IContent and Document, they get sorted but it seams like they get duplicated also ?, I guess that's because Im making a new item in the database by saving the node again after changing the sortnr.
is working on a reply...