Files
2026-10-08 10:43:59 +08:00

29 lines
1.3 KiB
C#

using F9WebAiTest.Application.Common.Exceptions;
using F9WebAiTest.Application.Interfaces.SnowflakeID;
using F9WebAiTest.Domain.Entities.SYS.RBAC;
using F9WebAiTest.Domain.Enums.SYS.RBAC;
using F9WebAiTest.Domain.Interfaces.SYS.RBAC.Menus;
using MediatR;
namespace F9WebAiTest.Application.CQRS.SYS.RBAC.Menus.Commands;
/// <summary>命令定义</summary>
public record Menu_UpdateCommand(long Id, string Name, string IconSvg, MenuType_Enum MenuType, string AssemblyName, string TypeFullName, long ParentId, int SortOrder) : IRequest<bool>;
/// <summary>命令处理器</summary>
public class UpdateMenuCommandHandler(
IMenuWriteRepository menuRepository) : IRequestHandler<Menu_UpdateCommand, bool>
{
public async Task<bool> Handle(Menu_UpdateCommand command, CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(command.Name)) throw new F9OperationException("菜单名称不能为空");
var menu = new Menu(command.Id, command.Name, command.IconSvg,
command.MenuType, command.AssemblyName, command.TypeFullName, command.ParentId, command.SortOrder);
var result = await menuRepository.UpdateAsync(menu);
if (result == false) throw new F9OperationException("菜单", "修改");
return result;
}
}