diff --git a/BootstrapAdmin-Blazor.slnf b/BootstrapAdmin-Blazor.slnf index 3e5291a2..b768597b 100644 --- a/BootstrapAdmin-Blazor.slnf +++ b/BootstrapAdmin-Blazor.slnf @@ -5,6 +5,7 @@ "src\\blazor\\admin\\BootstrapAdmin.DataAccess.EFCore\\BootstrapAdmin.DataAccess.EFCore.csproj", "src\\blazor\\admin\\BootstrapAdmin.DataAccess.Models\\BootstrapAdmin.DataAccess.Models.csproj", "src\\blazor\\admin\\BootstrapAdmin.DataAccess\\BootstrapAdmin.DataAccess.csproj", + "src\\blazor\\admin\\BootstrapAdmin.Web.Interface\\BootstrapAdmin.Web.Interface.csproj", "src\\blazor\\admin\\BootstrapAdmin.Web\\BootstrapAdmin.Web.csproj", "src\\mvc\\admin\\Bootstrap.Admin\\Bootstrap.Admin.csproj", "src\\mvc\\admin\\Bootstrap.DataAccess\\Bootstrap.DataAccess.csproj" diff --git a/BootstrapAdmin.sln b/BootstrapAdmin.sln index 68703490..295e5995 100644 --- a/BootstrapAdmin.sln +++ b/BootstrapAdmin.sln @@ -151,6 +151,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapAdmin.DataAccess.E EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapAdmin.DataAccess.Models", "src\blazor\admin\BootstrapAdmin.DataAccess.Models\BootstrapAdmin.DataAccess.Models.csproj", "{7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapAdmin.Web.Interface", "src\blazor\admin\BootstrapAdmin.Web.Interface\BootstrapAdmin.Web.Interface.csproj", "{C57CE871-FBC9-44B7-996B-E8D3449EDAD4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -209,6 +211,10 @@ Global {7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}.Debug|Any CPU.Build.0 = Debug|Any CPU {7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}.Release|Any CPU.ActiveCfg = Release|Any CPU {7E3861AB-F797-4A9F-B7CE-0E35751FFCD9}.Release|Any CPU.Build.0 = Release|Any CPU + {C57CE871-FBC9-44B7-996B-E8D3449EDAD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C57CE871-FBC9-44B7-996B-E8D3449EDAD4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C57CE871-FBC9-44B7-996B-E8D3449EDAD4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C57CE871-FBC9-44B7-996B-E8D3449EDAD4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -244,6 +250,7 @@ Global {1C04A3C2-DF68-4716-BA69-259CEC6E2311} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C} {D8ED2DF7-F7E1-4DE7-B097-D0BEE51D58E9} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C} {7E3861AB-F797-4A9F-B7CE-0E35751FFCD9} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C} + {C57CE871-FBC9-44B7-996B-E8D3449EDAD4} = {45ADEF9B-C8BD-4224-9E12-F6716E85A22C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {221EAE38-5F75-4391-9A48-E462A9F3B8FC} diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.csproj b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.csproj index 132c02c5..f5e11d6b 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.csproj +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.csproj @@ -1,9 +1,11 @@ - - net6.0 - enable - enable - + + + + + + + diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.xml b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.xml new file mode 100644 index 00000000..c11ea459 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.xml @@ -0,0 +1,59 @@ + + + + BootstrapAdmin.DataAccess.EFCore + + + + + + + + + + 构造函数 + + + + + + + + + + + + + + + + + + + + + + + + + + + 获得指定用户名可访问的所有菜单集合 + + 当前用户名 + 未层次化的菜单集合 + + + + + + + + + + + + + + + diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdminContext.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdminContext.cs new file mode 100644 index 00000000..7c705fbf --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdminContext.cs @@ -0,0 +1,37 @@ +using BootstrapAdmin.DataAccess.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BootstrapAdmin.DataAccess.EFCore +{ + /// + /// + /// + public class BootstrapAdminContext : DbContext + { + /// + /// 构造函数 + /// + /// + public BootstrapAdminContext(DbContextOptions options) : base(options) + { + + } + + /// + /// + /// + [NotNull] + public DbSet? Dicts { get; set; } + + /// + /// + /// + [NotNull] + public DbSet? Navigations { get; set; } + } +} diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Class1.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Class1.cs deleted file mode 100644 index 3efb7c69..00000000 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace BootstrapAdmin.DataAccess.EFCore -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Extensions/ServicesExtensions.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Extensions/ServicesExtensions.cs new file mode 100644 index 00000000..675106ad --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Extensions/ServicesExtensions.cs @@ -0,0 +1,35 @@ +using BootstrapAdmin.DataAccess.EFCore; +using BootstrapAdmin.DataAccess.EFCore.Services; +using BootstrapAdmin.DataAccess.Interface; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection.Extensions; + +namespace Microsoft.Extensions.DependencyInjection +{ + /// + /// + /// + public static class ServicesExtensions + { + /// + /// + /// + /// + /// + public static IServiceCollection AddEFCoreDataAccessServices(this IServiceCollection services) + { + services.AddDbContextFactory((provider, option) => + { + //TODO: 后期改造成自定适配 + var configuration = provider.GetRequiredService(); + var connString = configuration.GetConnectionString("bb"); + option.UseSqlite(connString); + }); + + services.TryAddSingleton(); + services.TryAddSingleton(); + return services; + } + } +} diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictsService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictsService.cs new file mode 100644 index 00000000..71ddf4f5 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictsService.cs @@ -0,0 +1,8 @@ +using BootstrapAdmin.DataAccess.Interface; + +namespace BootstrapAdmin.DataAccess.EFCore.Services +{ + class DictsService : IDicts + { + } +} diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/NavigationsService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/NavigationsService.cs new file mode 100644 index 00000000..e0c998fc --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/NavigationsService.cs @@ -0,0 +1,33 @@ +using BootstrapAdmin.DataAccess.EFCore; +using BootstrapAdmin.DataAccess.Interface; +using BootstrapAdmin.DataAccess.Models; +using Microsoft.EntityFrameworkCore; + +namespace BootstrapAdmin.DataAccess.EFCore.Services +{ + /// + /// + /// + class NavigationsService : INavigations + { + private IDbContextFactory DbFactory { get; set; } + + /// + /// + /// + /// + public NavigationsService(IDbContextFactory factory) => DbFactory = factory; + + /// + /// 获得指定用户名可访问的所有菜单集合 + /// + /// 当前用户名 + /// 未层次化的菜单集合 + public List RetrieveAllMenus(string userName) + { + using var context = DbFactory.CreateDbContext(); + //return context..Fetch($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID", new { UserName = userName, Category = "菜单", RoleName = "Administrators" }); + return new List(); + } + } +} diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/BootstrapAdmin.DataAccess.Models.csproj b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/BootstrapAdmin.DataAccess.Models.csproj index 132c02c5..61718a1f 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/BootstrapAdmin.DataAccess.Models.csproj +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/BootstrapAdmin.DataAccess.Models.csproj @@ -1,9 +1,3 @@ - - net6.0 - enable - enable - - diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.csproj b/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.csproj index 04834b3c..ae1a7260 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.csproj +++ b/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.csproj @@ -1,11 +1,5 @@  - - net6.0 - enable - enable - - @@ -14,11 +8,7 @@ - - - - - + diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.xml b/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.xml index fe3f04d3..7371ccd1 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.xml +++ b/src/blazor/admin/BootstrapAdmin.DataAccess/BootstrapAdmin.DataAccess.xml @@ -9,29 +9,13 @@ - + - - - Dict 字典表接口 - - - - - - - - - - - - - diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Extensions/ServicesExtensions.cs b/src/blazor/admin/BootstrapAdmin.DataAccess/Extensions/ServicesExtensions.cs index 5c4d0d7f..903c325f 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Extensions/ServicesExtensions.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess/Extensions/ServicesExtensions.cs @@ -1,4 +1,5 @@ -using BootstrapAdmin.DataAccess.Services; +using BootstrapAdmin.DataAccess.Interface; +using BootstrapAdmin.DataAccess.Services; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection.Extensions; using PetaPoco; @@ -16,7 +17,7 @@ namespace Microsoft.Extensions.DependencyInjection /// /// /// - public static IServiceCollection AddDataAccessServices(this IServiceCollection services) + public static IServiceCollection AddPetaPocoDataAccessServices(this IServiceCollection services) { services.TryAddSingleton(provider => { diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/DictsService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/DictsService.cs index e0f288fa..4c03f2c0 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/DictsService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/DictsService.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using BootstrapAdmin.DataAccess.Interface; namespace BootstrapAdmin.DataAccess.Services { diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/NavigationsService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/NavigationsService.cs index c18a3e26..22af3c89 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/NavigationsService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess/Services/NavigationsService.cs @@ -1,4 +1,5 @@ -using BootstrapAdmin.DataAccess.Models; +using BootstrapAdmin.DataAccess.Interface; +using BootstrapAdmin.DataAccess.Models; using PetaPoco; namespace BootstrapAdmin.DataAccess.Services @@ -8,13 +9,13 @@ namespace BootstrapAdmin.DataAccess.Services /// class NavigationsService : INavigations { - private IDatabase _db; + private IDatabase Database { get; set; } /// /// /// /// - public NavigationsService(IDatabase db) => _db = db; + public NavigationsService(IDatabase db) => Database = db; /// /// 获得指定用户名可访问的所有菜单集合 @@ -23,8 +24,8 @@ namespace BootstrapAdmin.DataAccess.Services /// 未层次化的菜单集合 public List RetrieveAllMenus(string userName) { - var order = _db.Provider.EscapeSqlIdentifier("Order"); - return _db.Fetch($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID", new { UserName = userName, Category = "菜单", RoleName = "Administrators" }); + var order = Database.Provider.EscapeSqlIdentifier("Order"); + return Database.Fetch($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID", new { UserName = userName, Category = "菜单", RoleName = "Administrators" }); } } } diff --git a/src/blazor/admin/BootstrapAdmin.Web.Interface/BootstrapAdmin.Web.Interface.csproj b/src/blazor/admin/BootstrapAdmin.Web.Interface/BootstrapAdmin.Web.Interface.csproj new file mode 100644 index 00000000..d1d3c3e7 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.Web.Interface/BootstrapAdmin.Web.Interface.csproj @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/blazor/admin/BootstrapAdmin.Web.Interface/BootstrapAdmin.Web.Interface.xml b/src/blazor/admin/BootstrapAdmin.Web.Interface/BootstrapAdmin.Web.Interface.xml new file mode 100644 index 00000000..7a993373 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.Web.Interface/BootstrapAdmin.Web.Interface.xml @@ -0,0 +1,24 @@ + + + + BootstrapAdmin.Web.Interface + + + + + Dict 字典表接口 + + + + + + + + + + + + + + + diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/IDicts.cs b/src/blazor/admin/BootstrapAdmin.Web.Interface/IDicts.cs similarity index 69% rename from src/blazor/admin/BootstrapAdmin.DataAccess/Services/IDicts.cs rename to src/blazor/admin/BootstrapAdmin.Web.Interface/IDicts.cs index 69f362ab..b321a8d0 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/IDicts.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Interface/IDicts.cs @@ -1,4 +1,4 @@ -namespace BootstrapAdmin.DataAccess.Services +namespace BootstrapAdmin.DataAccess.Interface { /// /// Dict 字典表接口 diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/INavigations.cs b/src/blazor/admin/BootstrapAdmin.Web.Interface/INavigations.cs similarity index 86% rename from src/blazor/admin/BootstrapAdmin.DataAccess/Services/INavigations.cs rename to src/blazor/admin/BootstrapAdmin.Web.Interface/INavigations.cs index 02e68470..810ecd69 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess/Services/INavigations.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Interface/INavigations.cs @@ -1,6 +1,6 @@ using BootstrapAdmin.DataAccess.Models; -namespace BootstrapAdmin.DataAccess.Services +namespace BootstrapAdmin.DataAccess.Interface { /// /// diff --git a/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.csproj b/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.csproj index 87ded732..118db74b 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.csproj +++ b/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.csproj @@ -1,10 +1,5 @@  - - net6.0 - enable - - @@ -16,7 +11,6 @@ - diff --git a/src/blazor/admin/BootstrapAdmin.Web/Extensions/ServicesExtensions.cs b/src/blazor/admin/BootstrapAdmin.Web/Extensions/ServicesExtensions.cs index 55cd6315..251fd653 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Extensions/ServicesExtensions.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Extensions/ServicesExtensions.cs @@ -69,7 +69,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddSingleton(); // 增加数据服务 - services.AddDataAccessServices(); + services.AddPetaPocoDataAccessServices(); return services; } diff --git a/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs index 898d4c68..bb5878da 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Shared/MainLayout.razor.cs @@ -1,4 +1,4 @@ -using BootstrapAdmin.DataAccess.Services; +using BootstrapAdmin.DataAccess.Interface; using BootstrapAdmin.Web.Extensions; namespace BootstrapAdmin.Web.Shared diff --git a/src/blazor/admin/Directory.Build.props b/src/blazor/admin/Directory.Build.props new file mode 100644 index 00000000..e85446f3 --- /dev/null +++ b/src/blazor/admin/Directory.Build.props @@ -0,0 +1,14 @@ + + + + + + net6.0 + enable + + + + + + +