diff --git a/zero.Core/Entities/Sections/Section.cs b/zero.Core/Entities/Sections/Section.cs new file mode 100644 index 00000000..b722632e --- /dev/null +++ b/zero.Core/Entities/Sections/Section.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; + +namespace zero.Core.Entities +{ + /// + /// A section is a main part of the backoffice application + /// + public class Section : ISection + { + /// + public string Alias { get; } + + /// + public string Name { get; } + + /// + public string Icon { get; } + + /// + public IList Children { get; } = new List(); + + + public Section() { } + + public Section(string alias, string name, string icon) + { + Alias = alias; + Name = name; + Icon = icon; + } + } +} diff --git a/zero.Core/Entities/Sections/SectionCollection.cs b/zero.Core/Entities/Sections/SectionCollection.cs new file mode 100644 index 00000000..9144424e --- /dev/null +++ b/zero.Core/Entities/Sections/SectionCollection.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace zero.Core.Entities.Sections +{ + public class SectionCollection : List + { + public void Add() where T : ISection, new() + { + Add(new T()); + } + + public void Add(string alias, string name, string icon) + { + Add(new Section(alias, name, icon)); + } + } +} diff --git a/zero.Core/ZeroOptions.cs b/zero.Core/ZeroOptions.cs new file mode 100644 index 00000000..b5b1a1f1 --- /dev/null +++ b/zero.Core/ZeroOptions.cs @@ -0,0 +1,9 @@ +using zero.Core.Entities.Sections; + +namespace zero.Core +{ + public class ZeroOptions + { + public SectionCollection Sections { get; private set; } = new SectionCollection(); + } +} diff --git a/zero.Web/Controllers/IndexController.cs b/zero.Web/Controllers/IndexController.cs index 061c1b47..c57a9975 100644 --- a/zero.Web/Controllers/IndexController.cs +++ b/zero.Web/Controllers/IndexController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using zero.Core; using zero.Core.Extensions; @@ -8,7 +9,7 @@ namespace zero.Web.Controllers [AllowAnonymous] public class IndexController : BackofficeController { - public IndexController(IZeroConfiguration config) : base(config) + public IndexController(IZeroConfiguration config, IOptionsMonitor options) : base(config) { } diff --git a/zero.Web/Controllers/SetupController.cs b/zero.Web/Controllers/SetupController.cs index d56210a6..b7ce349c 100644 --- a/zero.Web/Controllers/SetupController.cs +++ b/zero.Web/Controllers/SetupController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using System; using System.Linq; @@ -21,7 +22,7 @@ namespace zero.Web.Setup protected IWebHostEnvironment Environment { get; private set; } - public SetupController(IZeroConfiguration config, ISetupApi api, IWebHostEnvironment env) : base(config) + public SetupController(IZeroConfiguration config, ISetupApi api, IWebHostEnvironment env) : base(config) // UserManager userManager { Api = api; Environment = env; diff --git a/zero.Web/ServiceCollectionExtensions.cs b/zero.Web/ServiceCollectionExtensions.cs new file mode 100644 index 00000000..9a6afd2b --- /dev/null +++ b/zero.Web/ServiceCollectionExtensions.cs @@ -0,0 +1,30 @@ +using Microsoft.Extensions.DependencyInjection; +using System; +using zero.Core; +using zero.Web.Sections; + +namespace zero.Web +{ + public static class ServiceCollectionExtensions + { + public static IServiceCollection AddZero(this IServiceCollection services) + { + services.AddOptions() + .Configure(opts => + { + opts.Sections.Add(); + opts.Sections.Add(); + opts.Sections.Add(); + opts.Sections.Add(); + opts.Sections.Add(); + }); + + return services; + } + + public static IServiceCollection AddZero(this IServiceCollection services, Action setupAction) + { + return services.AddZero().PostConfigure(setupAction); + } + } +} diff --git a/zero.Web/Startup.cs b/zero.Web/Startup.cs index f456e6a7..756845ad 100644 --- a/zero.Web/Startup.cs +++ b/zero.Web/Startup.cs @@ -13,6 +13,7 @@ using System; using System.Threading.Tasks; using zero.Core; using zero.Core.Api; +using zero.Web.Sections; namespace zero.Web { @@ -51,6 +52,11 @@ namespace zero.Web // add zero core //services.AddCore(appConfig, env); + services.AddZero(opts => + { + //opts.Sections.RemoveAt(1); + //opts.Sections.Add("ecommerce", "E-Commerce", "shopping-bag"); + }); // add cookie-based authentication services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)