添加角色中文名支持并实现删除角色功能
This commit is contained in:
parent
e93fb5b5a9
commit
24072ee81a
@ -53,20 +53,21 @@ public class AdminRoleControllers:ControllerBase
|
||||
/// 管理员角色控制器,用于处理与角色相关的操作,如添加角色、分配角色给用户以及通过角色查询用户。
|
||||
/// 该控制器下的所有方法都需要管理员权限才能访问。
|
||||
/// </summary>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加新角色
|
||||
/// </summary>
|
||||
/// <param name="role">要添加的角色信息</param>
|
||||
/// <param name="rolename">角色名</param>
|
||||
/// <param name="normalizedname">可以不填</param>
|
||||
/// <param name="ChineseName">中文名</param>
|
||||
/// <returns>返回操作结果,包含状态码、消息和数据</returns>
|
||||
[HttpPost("role")]
|
||||
public async Task<IActionResult> AddRole(string rolename,string normalizedname)
|
||||
public async Task<IActionResult> 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,"创建成功",""));
|
||||
@ -78,6 +79,30 @@ public class AdminRoleControllers:ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[HttpDelete("role")]
|
||||
public async Task<IActionResult> 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))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 为指定用户分配角色
|
||||
/// </summary>
|
||||
|
@ -55,6 +55,10 @@ namespace AGSS.Migrations
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("character varying(1000)");
|
||||
|
||||
b.Property<string>("MenuName")
|
||||
.HasMaxLength(1000)
|
||||
.HasColumnType("character varying(1000)");
|
||||
|
||||
b.Property<string>("ParentId")
|
||||
.HasMaxLength(150)
|
||||
.HasColumnType("character varying(150)");
|
||||
@ -91,6 +95,9 @@ namespace AGSS.Migrations
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ChineseName")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("text");
|
||||
|
@ -25,5 +25,6 @@ public class UserModel:IdentityUser<string>
|
||||
|
||||
public class RoleModel : IdentityRole<string>
|
||||
{
|
||||
public string? ChineseName { get; set; }
|
||||
|
||||
}
|
28
script.sql
28
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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user