From 24072ee81ab231c511afca552fdc44ef39e9c519 Mon Sep 17 00:00:00 2001 From: luolan Date: Sat, 19 Jul 2025 22:36:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A7=92=E8=89=B2=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E5=90=8D=E6=94=AF=E6=8C=81=E5=B9=B6=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=A7=92=E8=89=B2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/AdminRoleControllers.cs | 35 ++++++++++++++++--- .../ApplicationDbContextModelSnapshot.cs | 7 ++++ AGSS/Models/Entities/User.cs | 1 + script.sql | 28 ++------------- 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/AGSS/Controllers/Admin/AdminRoleControllers.cs b/AGSS/Controllers/Admin/AdminRoleControllers.cs index 606369c..ad5b948 100644 --- a/AGSS/Controllers/Admin/AdminRoleControllers.cs +++ b/AGSS/Controllers/Admin/AdminRoleControllers.cs @@ -53,23 +53,24 @@ public class AdminRoleControllers:ControllerBase /// 管理员角色控制器,用于处理与角色相关的操作,如添加角色、分配角色给用户以及通过角色查询用户。 /// 该控制器下的所有方法都需要管理员权限才能访问。 /// - - /// /// 添加新角色 /// /// 要添加的角色信息 + /// 角色名 + /// 可以不填 + /// 中文名 /// 返回操作结果,包含状态码、消息和数据 [HttpPost("role")] - public async Task AddRole(string rolename,string normalizedname) + public async Task AddRole(string rolename,string normalizedname,string ChineseName) { - var result = await _roleManager.CreateAsync(new RoleModel(){Id = Guid.Empty.ToString(),Name = rolename,NormalizedName = normalizedname}); + var result = await _roleManager.CreateAsync(new RoleModel(){Id = Guid.NewGuid().ToString(),Name = rolename,NormalizedName = normalizedname,ChineseName = ChineseName}); if (result.Succeeded) { - return Ok(new ReturnTemplate(200,"创建成功","")); + return Ok(new ReturnTemplate(200,"创建成功","")); } else @@ -77,6 +78,30 @@ public class AdminRoleControllers:ControllerBase return Ok(new ReturnTemplate(StatusCodes.Status500InternalServerError,"创建失败","Failed to create role: " + string.Join(", ", result.Errors.Select(e => e.Description)))); } } + + + + + [HttpDelete("role")] + public async Task DelRole(string id) + { + + + var delrole = await _roleManager.FindByIdAsync(id); + var result = await _roleManager.DeleteAsync(delrole); + if (result.Succeeded) + { + return Ok(new ReturnTemplate(200,"成功了呢,贝贝","")); + + } + else + { + return Ok(new ReturnTemplate(StatusCodes.Status500InternalServerError,"失败了呢,贝贝","Failed to delect role: " + string.Join(", ", result.Errors.Select(e => e.Description)))); + } + } + + + /// /// 为指定用户分配角色 diff --git a/AGSS/Migrations/ApplicationDbContextModelSnapshot.cs b/AGSS/Migrations/ApplicationDbContextModelSnapshot.cs index 490eb3c..f5a10c8 100644 --- a/AGSS/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/AGSS/Migrations/ApplicationDbContextModelSnapshot.cs @@ -55,6 +55,10 @@ namespace AGSS.Migrations .HasMaxLength(1000) .HasColumnType("character varying(1000)"); + b.Property("MenuName") + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + b.Property("ParentId") .HasMaxLength(150) .HasColumnType("character varying(150)"); @@ -91,6 +95,9 @@ namespace AGSS.Migrations b.Property("Id") .HasColumnType("text"); + b.Property("ChineseName") + .HasColumnType("text"); + b.Property("ConcurrencyStamp") .IsConcurrencyToken() .HasColumnType("text"); diff --git a/AGSS/Models/Entities/User.cs b/AGSS/Models/Entities/User.cs index 242326c..1f4a27e 100644 --- a/AGSS/Models/Entities/User.cs +++ b/AGSS/Models/Entities/User.cs @@ -25,5 +25,6 @@ public class UserModel:IdentityUser public class RoleModel : IdentityRole { + public string? ChineseName { get; set; } } \ No newline at end of file diff --git a/script.sql b/script.sql index ef682b8..7dc69af 100644 --- a/script.sql +++ b/script.sql @@ -1,32 +1,10 @@ START TRANSACTION; -DROP TABLE "Dictionaries"; +ALTER TABLE "Menus" ADD "MenuName" character varying(1000); -CREATE TABLE "DictItems" ( - "Uuid" uuid NOT NULL, - parentid uuid, - parentvalue text, - label character varying(100) NOT NULL, - "LabelEn" character varying(100), - "Remark" character varying(500), - value character varying(50) NOT NULL, - tag character varying(500), - createtime timestamp with time zone NOT NULL, - "CreateUserId" uuid NOT NULL, - CONSTRAINT "PK_DictItems" PRIMARY KEY ("Uuid"), - CONSTRAINT "CK_TopLevelItems" CHECK (ParentId IS NULL OR (Tag IS NOT NULL AND ParentValue IS NOT NULL)), - CONSTRAINT "FK_DictItems_DictItems_parentid" FOREIGN KEY (parentid) REFERENCES "DictItems" ("Uuid") ON DELETE CASCADE -); - -CREATE INDEX "IX_DictItems_parentid" ON "DictItems" (parentid); - -CREATE INDEX "IX_DictItems_parentvalue" ON "DictItems" (parentvalue); - -CREATE INDEX "IX_DictItems_tag" ON "DictItems" (tag); - -CREATE INDEX "IX_DictItems_value" ON "DictItems" (value); +ALTER TABLE "AspNetRoles" ADD "ChineseName" text; INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") -VALUES ('20250715135627_dic1', '9.0.6'); +VALUES ('20250719094443_roleaddchinses', '9.0.6'); COMMIT;