diff --git a/IRaCIS.Core.Application/Service/Management/UserService.cs b/IRaCIS.Core.Application/Service/Management/UserService.cs index 60822a9d9..72fa8af47 100644 --- a/IRaCIS.Core.Application/Service/Management/UserService.cs +++ b/IRaCIS.Core.Application/Service/Management/UserService.cs @@ -1140,8 +1140,6 @@ namespace IRaCIS.Core.Application.Service { var jwt = _tokenService.GetToken(userTokenInfo); - - return jwt; } else diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs index f16fa9675..140cdf627 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs @@ -4,6 +4,7 @@ using IRaCIS.Application.Interfaces; using IRaCIS.Core.Application.Contracts.DTO; using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Domain.Share; +using MassTransit.Serialization; using Microsoft.AspNetCore.Mvc; namespace IRaCIS.Core.Application.Service @@ -174,23 +175,33 @@ namespace IRaCIS.Core.Application.Service //[Authorize(Policy = IRaCISPolicy.PM_APM)] public async Task AddTrialUsers(TrialUserAddCommand[] userTrialCommands) { - foreach (var item in userTrialCommands.GroupBy(t => t.IdentityUserId)) { var currentUserRoleList = item.ToList(); var first = currentUserRoleList.FirstOrDefault(); - var currentUser = new TrialIdentityUser() + var findTrialuser = await _trialIdentityUserRepository.Where(t => t.TrialId == first.TrialId && t.IdentityUserId == item.Key, true).Include(t => t.TrialUserRoleList).FirstOrDefaultAsync(); + + if (findTrialuser == null) { - TrialId = first.TrialId, - IdentityUserId = item.Key, - JoinTime = DateTime.Now, - TrialUserRoleList = currentUserRoleList.Select(t => new TrialUserRole() { UserId = t.UserId, TrialId = t.TrialId }).ToList() - }; + var currentUser = new TrialIdentityUser() + { + TrialId = first.TrialId, + IdentityUserId = item.Key, + JoinTime = DateTime.Now, + TrialUserRoleList = currentUserRoleList.Select(t => new TrialUserRole() { UserId = t.UserId, TrialId = t.TrialId }).ToList() + }; + + + await _trialIdentityUserRepository.AddAsync(currentUser); + } + else + { + findTrialuser.TrialUserRoleList.AddRange(currentUserRoleList.Select(t => new TrialUserRole() { UserId = t.UserId, TrialId = t.TrialId, TrialUserId = findTrialuser.Id }).ToList()); + } - await _trialIdentityUserRepository.AddAsync(currentUser); var success = await _trialIdentityUserRepository.SaveChangesAsync();