From 4ab0bcef19b78f9ae0339d4b78de68a7297f7683 Mon Sep 17 00:00:00 2001
From: sunpengfei <i@angelzzz.com>
Date: 星期四, 28 八月 2025 14:54:15 +0800
Subject: [PATCH] Merge branch 'master' of http://120.26.58.240:8888/r/ApiFlexJob

---
 FlexJobApi.UserServer.Application/Users/Commands/UserInfoCommandHandler.cs |   30 ++++++++++++++++++++++++++++--
 1 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/FlexJobApi.UserServer.Application/Users/Commands/UserInfoCommandHandler.cs b/FlexJobApi.UserServer.Application/Users/Commands/UserInfoCommandHandler.cs
index b91f501..f2c78f9 100644
--- a/FlexJobApi.UserServer.Application/Users/Commands/UserInfoCommandHandler.cs
+++ b/FlexJobApi.UserServer.Application/Users/Commands/UserInfoCommandHandler.cs
@@ -1,5 +1,6 @@
 锘縰sing FlexJobApi.Core;
 using Furion.DatabaseAccessor;
+using Furion.FriendlyException;
 using MediatR;
 using Microsoft.EntityFrameworkCore;
 using System;
@@ -15,8 +16,9 @@
     /// </summary>
     public class UserInfoCommandHandler(
             IRepository<User> rep
-        ) : 
-        IRequestHandler<SetUserInfoStatusCommand, int>
+        ) :
+        IRequestHandler<SetUserInfoStatusCommand, int>,
+        IRequestHandler<SetUserInfoRolesCommand, int>
     {
         private readonly IRepository<User> rep = rep;
 
@@ -37,5 +39,29 @@
             }
             return entities.Count;
         }
+
+        /// <summary>
+        /// 璁剧疆鐢ㄦ埛淇℃伅瑙掕壊
+        /// </summary>
+        /// <param name="request"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        public async Task<int> Handle(SetUserInfoRolesCommand request, CancellationToken cancellationToken)
+        {
+            var entity = await rep.AsQueryable()
+                .Include(it => it.UserRoles)
+                .Where(it => it.Id == request.UserInfoId)
+                .FirstOrDefaultAsync(cancellationToken);
+            if (entity == null) throw Oops.Oh(EnumErrorCodeType.s404, "鐢ㄦ埛");
+            entity.UserRoles = request.RoleIds
+                .Select(it => new UserRole
+                {
+                    RoleId = it
+                })
+                .ToList();
+            await rep.UpdateAsync(entity);
+            return entity.UserRoles.Count;
+        }
+
     }
 }

--
Gitblit v1.9.1