From 53774d88561cc1a35bdf645bc95109d42185b4c4 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Wed, 30 Mar 2022 14:07:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=96=E9=83=A8=E7=94=A8=E6=88=B7=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=82=AE=E4=BB=B6bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/SiteSurvey/_MapConfig.cs | 7 +++++-- .../TrialSiteUser/TrialExternalUserService.cs | 2 +- .../Service/TrialSiteUser/TrialMaintenanceService.cs | 12 ++++++------ .../Repository/ICommandRepository.cs | 3 +++ IRaCIS.Core.Infra.EFCore/Repository/Repository.cs | 5 +++++ 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/IRaCIS.Core.Application/Service/SiteSurvey/_MapConfig.cs b/IRaCIS.Core.Application/Service/SiteSurvey/_MapConfig.cs index 18baa2f37..322b1cef5 100644 --- a/IRaCIS.Core.Application/Service/SiteSurvey/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/SiteSurvey/_MapConfig.cs @@ -34,7 +34,7 @@ namespace IRaCIS.Core.Application.AutoMapper .ForMember(d => d.TrialSiteCode, u => u.MapFrom(s => s.TrialSite.TrialSiteCode)); CreateMap() - .ForMember(t => t.TrialRoleName, u => u.MapFrom(d => d.TrialRoleName.Value)) + .ForMember(t => t.TrialRoleName, u => u.MapFrom(d => d.TrialRoleName.Value)) .ForMember(d => d.UserType, u => u.MapFrom(s => s.UserTypeRole.UserTypeShortName)); @@ -61,7 +61,10 @@ namespace IRaCIS.Core.Application.AutoMapper - CreateMap().ForMember(t=>t.TrialSiteSurvey,u=>u.MapFrom(c=>c.TrialSiteSurvey)); + CreateMap() + .ForMember(t=>t.TrialSiteSurvey,u=>u.MapFrom(c=>c.TrialSiteSurvey)) + .ForMember(t => t.TrialRoleName, u => u.MapFrom(d => d.TrialRoleName.Value)) + .ForMember(d => d.UserType, u => u.MapFrom(s => s.UserTypeRole.UserTypeShortName)); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs index 96d968371..c56b8a80a 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialExternalUserService.cs @@ -127,6 +127,7 @@ namespace IRaCIS.Core.Application.Service addEntity.IsSystemUser = false; addEntity.SystemUserId = newAddUser.Id; + await _trialExternalUseRepository.SaveChangesAsync(); } @@ -151,7 +152,6 @@ namespace IRaCIS.Core.Application.Service }); } - await _trialExternalUseRepository.SaveChangesAsync(); return ResponseOutput.Ok(addEntity.Id.ToString()); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs index fbf8f8682..b2ef36bac 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs @@ -38,7 +38,7 @@ namespace IRaCIS.Application.Services .WhereIf(!string.IsNullOrWhiteSpace(param.UserRealName), t => (t.User.LastName + " / " + t.User.FirstName).Contains(param.UserRealName)) .ProjectTo(_mapper.ConfigurationProvider); - return await query.ToPagedListAsync(param.PageIndex,param.PageSize, string.IsNullOrWhiteSpace(param.SortField) ? "UpdateTime" : param.SortField, param.Asc); + return await query.ToPagedListAsync(param.PageIndex, param.PageSize, string.IsNullOrWhiteSpace(param.SortField) ? "UpdateTime" : param.SortField, param.Asc); } @@ -60,7 +60,7 @@ namespace IRaCIS.Application.Services return await query.ToPagedListAsync(param.PageIndex, param.PageSize, string.IsNullOrWhiteSpace(param.SortField) ? "UpdateTime" : param.SortField, param.Asc); - + } @@ -96,11 +96,11 @@ namespace IRaCIS.Application.Services { var addArray = _mapper.Map(userTrialCommands); - await _repository.AddRangeAsync(addArray); + var trialUsers = await _trialUseRepository.AddRangeAsync(addArray); - foreach (var item in addArray) + foreach (var item in trialUsers) { - item.JoinTime = item.CreateTime; + item.JoinTime = DateTime.Now; } @@ -115,7 +115,7 @@ namespace IRaCIS.Application.Services [HttpPut] public async Task UpdateTrialUser(UpdateTrialUserCommand updateTrialUserCommand) { - var trialUser = await _trialUseRepository.Where(t => t.Id == updateTrialUserCommand.Id,true,true).FirstOrDefaultAsync(); + var trialUser = await _trialUseRepository.Where(t => t.Id == updateTrialUserCommand.Id, true, true).FirstOrDefaultAsync(); if (trialUser == null) return Null404NotFound(trialUser); diff --git a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs index fd8480485..c8fcb93e7 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/ICommandRepository.cs @@ -28,6 +28,9 @@ namespace IRaCIS.Core.Infra.EFCore Task CountAsync(Expression> whereLambda = null, bool ignoreQueryFilters = false); ValueTask AddAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); + + Task> AddRangeAsync(IEnumerable entities); + Task AddRangeAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default); // 不建议使用,使用跟踪,然后save 部分字段更新,此种方式是更新所有字段 Task UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 9c0d98310..6040884df 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -139,7 +139,12 @@ namespace IRaCIS.Core.Infra.EFCore return entity; } + public async Task> AddRangeAsync(IEnumerable entities) + { + await _dbSet.AddRangeAsync(entities).ConfigureAwait(false); + return entities; + } public async Task AddRangeAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) { await _dbSet.AddRangeAsync(entities).ConfigureAwait(false);