This commit is contained in:
parent
8aba94f721
commit
75ddaf8931
|
|
@ -3,6 +3,11 @@ using Umbraco.Cms.Core.Web;
|
|||
using Umbraco.Cms.Core.Models.PublishedContent;
|
||||
using Newtonsoft.Json;
|
||||
using System.Data;
|
||||
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
|
||||
using System.Text.Json;
|
||||
using Umbraco.Cms.Core;
|
||||
using System.Reflection;
|
||||
using System.Dynamic;
|
||||
|
||||
|
||||
namespace UmbracoDocs.Samples;
|
||||
|
|
@ -35,7 +40,13 @@ public class GetMenuController : Controller
|
|||
new DataColumn("id", typeof(int)),
|
||||
new DataColumn("name", typeof(string)),
|
||||
new DataColumn("type", typeof(string)),
|
||||
new DataColumn("parentid", typeof(int))
|
||||
new DataColumn("slug", typeof(string)),
|
||||
new DataColumn("parentid", typeof(int)),
|
||||
new DataColumn("position", typeof(int)) {
|
||||
AutoIncrement = true,
|
||||
AutoIncrementSeed = 1, // Początkowa wartość
|
||||
AutoIncrementStep = 1 // Krok zwiększania
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -54,26 +65,26 @@ public class GetMenuController : Controller
|
|||
|
||||
var result = (
|
||||
from org in dataTable.AsEnumerable()
|
||||
where
|
||||
where
|
||||
org.Field<string>("type") == "organization" &&
|
||||
org.Field<string>("name")!.ToLower() == Uri.UnescapeDataString(organization).ToLower()
|
||||
from
|
||||
from
|
||||
dom in dataTable.AsEnumerable()
|
||||
where
|
||||
where
|
||||
dom.Field<int?>("parentid") == org.Field<int>("id") &&
|
||||
dom.Field<string>("type") == "domains" &&
|
||||
dom.Field<string>("name")!.ToLower() == Uri.UnescapeDataString(domain).ToLower()
|
||||
join child in dataTable.AsEnumerable() on dom.Field<int>("id") equals child.Field<int?>("parentid")
|
||||
select child)
|
||||
.Union(
|
||||
from
|
||||
from
|
||||
org in dataTable.AsEnumerable()
|
||||
where
|
||||
where
|
||||
org.Field<string>("type") == "organization" &&
|
||||
org.Field<string>("name")!.ToLower() == Uri.UnescapeDataString(organization).ToLower()
|
||||
from
|
||||
from
|
||||
dom in dataTable.AsEnumerable()
|
||||
where
|
||||
where
|
||||
dom.Field<int?>("parentid") == org.Field<int>("id") &&
|
||||
dom.Field<string>("type") == "domains" &&
|
||||
dom.Field<string>("name")!.ToLower() == Uri.UnescapeDataString(domain).ToLower()
|
||||
|
|
@ -84,8 +95,10 @@ public class GetMenuController : Controller
|
|||
{
|
||||
id = child.Field<int>("id"),
|
||||
name = child.Field<string>("name"),
|
||||
slug = child.Field<string>("slug"),
|
||||
type = child.Field<string>("type"),
|
||||
parentid = child.Field<int?>("parentid")
|
||||
parentid = child.Field<int?>("parentid"),
|
||||
position = child.Field<int?>("position")
|
||||
});
|
||||
|
||||
var allIds = result.Select(row => row.id).ToHashSet();
|
||||
|
|
@ -94,7 +107,9 @@ public class GetMenuController : Controller
|
|||
id = row.id,
|
||||
name = row.name,
|
||||
type = row.type,
|
||||
parentid = row.parentid.HasValue && !allIds.Contains(row.parentid.Value) ? (int?)null : row.parentid
|
||||
slug = row.slug,
|
||||
parentid = row.parentid.HasValue && !allIds.Contains(row.parentid.Value) ? (int?)null : row.parentid,
|
||||
position = row.position
|
||||
}).ToList();
|
||||
|
||||
Console.WriteLine(JsonConvert.SerializeObject(modifiedResult, Formatting.Indented));
|
||||
|
|
@ -132,7 +147,8 @@ public class GetMenuController : Controller
|
|||
x.Id,
|
||||
x.Name,
|
||||
x.ContentType.Alias,
|
||||
x.Parent?.Id ?? null!
|
||||
x.Value<string>("slug") ?? null!,
|
||||
x.Parent?.Id ?? null!,
|
||||
}, LoadOption.PreserveChanges);
|
||||
if (x.Children != null && x.Children.Any())
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue