// POST: api/UserRole attach user role,id is userId public async Task <HandleResult> Post(string id, [FromBody] List <string> roleIds) { var command = new AttachUserRole(id, roleIds); var result = await ExecuteCommandAsync(command); if (result.IsSuccess()) { return(HandleResult.FromSuccess("设置成功")); } return(HandleResult.FromFail(result.GetErrorMessage())); }
/// <summary>添加用户角色 /// </summary> public void Handle(ICommandContext context, AttachUserRole command) { _lockService.ExecuteInLock(typeof(User).Name, () => { foreach (var roleId in command.RoleIds) { _roleService.IsEnabled(roleId); } context.Get <User>(command.AggregateRootId).AttachUserRole(command.RoleIds); }); }