diff --git a/POKASH/CustomAPI/GetMenu.cs b/POKASH/CustomAPI/GetMenu.cs index 8b233ae..1f27c09 100644 --- a/POKASH/CustomAPI/GetMenu.cs +++ b/POKASH/CustomAPI/GetMenu.cs @@ -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("type") == "organization" && org.Field("name")!.ToLower() == Uri.UnescapeDataString(organization).ToLower() - from + from dom in dataTable.AsEnumerable() - where + where dom.Field("parentid") == org.Field("id") && dom.Field("type") == "domains" && dom.Field("name")!.ToLower() == Uri.UnescapeDataString(domain).ToLower() join child in dataTable.AsEnumerable() on dom.Field("id") equals child.Field("parentid") select child) .Union( - from + from org in dataTable.AsEnumerable() - where + where org.Field("type") == "organization" && org.Field("name")!.ToLower() == Uri.UnescapeDataString(organization).ToLower() - from + from dom in dataTable.AsEnumerable() - where + where dom.Field("parentid") == org.Field("id") && dom.Field("type") == "domains" && dom.Field("name")!.ToLower() == Uri.UnescapeDataString(domain).ToLower() @@ -84,8 +95,10 @@ public class GetMenuController : Controller { id = child.Field("id"), name = child.Field("name"), + slug = child.Field("slug"), type = child.Field("type"), - parentid = child.Field("parentid") + parentid = child.Field("parentid"), + position = child.Field("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("slug") ?? null!, + x.Parent?.Id ?? null!, }, LoadOption.PreserveChanges); if (x.Children != null && x.Children.Any()) {