diff --git a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs index c402e1f3d..7c133f4f4 100644 --- a/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs +++ b/IRaCIS.Core.Application/Service/Management/DTO/UserModel.cs @@ -211,6 +211,13 @@ namespace IRaCIS.Application.Contracts public Guid Id { get; set; } } + public class UpdateUserRolesDto + { + public Guid Id { get; set; } + + public List UserRoleList { get; set; } + } + public class UserCommand : UserInfo { public Guid? Id { get; set; } diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index d811fe95e..bb457e4ea 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -500,26 +500,7 @@ namespace IRaCIS.Core.Application.Service return user; } - ///// - ///// 删除用户 - ///// - ///// - ///// - //[HttpDelete("{userId:guid}")] - //public async Task DeleteUser(Guid userId) - //{ - // if (await _userTrialRepository.AnyAsync(t => t.Id == userId)) - // { - // //---该用户已经参加项目,不能够删除。 - // return ResponseOutput.NotOk(_localizer["User_InProject"]); - // } - // await _userLogRepository.AddAsync(new UserLog() { IP = _userInfo.IP, LoginUserId = _userInfo.Id, OptUserId = userId, OptType = UserOptType.DeleteUser }, true); - - // var success = await _userRoleRepository.BatchDeleteNoTrackingAsync(t => t.Id == userId); - - // return ResponseOutput.Result(success); - //} /// @@ -671,6 +652,40 @@ namespace IRaCIS.Core.Application.Service } + [HttpPut] + public async Task UpdateUserRoleInfo(UpdateUserRolesDto command) + { + var user = await _identityUserRepository.Where(t => t.Id == command.Id, true).Include(t => t.UserRoleList).FirstOrDefaultAsync(); + + if (user == null) return Null404NotFound(user); + + foreach (var role in command.UserRoleList) + { + var find = user.UserRoleList.FirstOrDefault(t => t.UserTypeEnum == role.UserTypeEnum && t.UserTypeId == role.UserTypeId); + + if (find != null) + { + find.IsUserRoleDisabled = role.IsUserRoleDisabled; + } + else + { + var addRole = _mapper.Map(user); + + addRole.Id = NewId.NextSequentialGuid(); + addRole.IdentityUserId = user.Id; + addRole.UserTypeEnum = role.UserTypeEnum; + addRole.UserTypeId = role.UserTypeId; + + user.UserRoleList.Add(addRole); + } + } + + + var success = await _userRoleRepository.SaveChangesAsync(); + + return ResponseOutput.Ok(); + } + ///// ///// 禁用或者启用账户 ///// diff --git a/IRaCIS.Core.Application/Service/Management/_MapConfig.cs b/IRaCIS.Core.Application/Service/Management/_MapConfig.cs index 08ffd85b1..cb220bcd0 100644 --- a/IRaCIS.Core.Application/Service/Management/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Management/_MapConfig.cs @@ -1,5 +1,6 @@ using AutoMapper; using AutoMapper.EquivalencyExpression; +using DocumentFormat.OpenXml.Spreadsheet; using IRaCIS.Application.Contracts; using IRaCIS.Core.Application.Auth; using IRaCIS.Core.Application.Contracts; @@ -163,6 +164,8 @@ namespace IRaCIS.Core.Application.Service .ForMember(d => d.UserTypeShortName, c => c.MapFrom(t => t.UserTypeRole.UserTypeShortName)); CreateMap(); + + CreateMap(); } }