diff --git a/src/Spd.Manager.Licence/BizMemberManager.cs b/src/Spd.Manager.Licence/BizMemberManager.cs index f69ed1edc..579ae64fb 100644 --- a/src/Spd.Manager.Licence/BizMemberManager.cs +++ b/src/Spd.Manager.Licence/BizMemberManager.cs @@ -165,7 +165,7 @@ public async Task Handle(GetBizMembersQuery qry, CancellationToken ct) .Where(c => c.BizContactRoleCode == BizContactRoleEnum.ControllingMember) .Select(c => _mapper.Map(c)); members.Employees = bizMembers.Where(c => c.ContactId != null && c.LicenceId != null) - .Where(c => c.BizContactRoleCode == BizContactRoleEnum.Employee) + .Where(c => c.BizContactRoleCode == BizContactRoleEnum.Employee && !c.PositionCodes.Any(c => c == PositionEnum.PrivateInvestigatorManager)) .Select(c => _mapper.Map(c)); return members; } diff --git a/src/Spd.Resource.Repository/BizContact/BizContactRepository.cs b/src/Spd.Resource.Repository/BizContact/BizContactRepository.cs index 0b72cde3c..1300dd865 100644 --- a/src/Spd.Resource.Repository/BizContact/BizContactRepository.cs +++ b/src/Spd.Resource.Repository/BizContact/BizContactRepository.cs @@ -1,7 +1,6 @@ using AutoMapper; using Microsoft.Dynamics.CRM; using Microsoft.Extensions.Logging; -using Spd.Resource.Repository.PersonLicApplication; using Spd.Utilities.Dynamics; using Spd.Utilities.Shared.Exceptions; using System.Net; @@ -41,6 +40,7 @@ public BizContactRepository(IDynamicsContextFactory ctx, public async Task> QueryBizContactsAsync(BizContactQry qry, CancellationToken ct) { IQueryable bizContacts = _context.spd_businesscontacts + .Expand(c => c.spd_position_spd_businesscontact) .Expand(c => c.spd_businesscontact_spd_application) .Expand(c => c.spd_businesscontact_spd_portalinvitation); diff --git a/src/Spd.Resource.Repository/BizContact/Contract.cs b/src/Spd.Resource.Repository/BizContact/Contract.cs index 87a0da2ab..d5a56a3c5 100644 --- a/src/Spd.Resource.Repository/BizContact/Contract.cs +++ b/src/Spd.Resource.Repository/BizContact/Contract.cs @@ -1,4 +1,5 @@ using Spd.Resource.Repository.Application; +using Spd.Resource.Repository.BizLicApplication; namespace Spd.Resource.Repository.BizContact { @@ -39,6 +40,7 @@ public record BizContact public Guid? ContactId { get; set; } public Guid? LicenceId { get; set; } public BizContactRoleEnum BizContactRoleCode { get; set; } = BizContactRoleEnum.ControllingMember; + public IEnumerable PositionCodes { get; set; } = Enumerable.Empty(); public Guid BizId { get; set; } } diff --git a/src/Spd.Resource.Repository/BizContact/Mappings.cs b/src/Spd.Resource.Repository/BizContact/Mappings.cs index 2cee5c114..935a1ef1b 100644 --- a/src/Spd.Resource.Repository/BizContact/Mappings.cs +++ b/src/Spd.Resource.Repository/BizContact/Mappings.cs @@ -1,6 +1,7 @@ using AutoMapper; using Microsoft.Dynamics.CRM; using Spd.Resource.Repository.Application; +using Spd.Resource.Repository.BizLicApplication; using Spd.Utilities.Dynamics; namespace Spd.Resource.Repository.BizContact @@ -23,6 +24,7 @@ public Mappings() .IncludeBase() .ForMember(d => d.BizContactId, opt => opt.MapFrom(s => s.spd_businesscontactid)) .ForMember(d => d.BizContactRoleCode, opt => opt.MapFrom(s => SharedMappingFuncs.GetEnum(s.spd_role))) + .ForMember(d => d.PositionCodes, opt => opt.MapFrom(s => GetPositions(s.spd_position_spd_businesscontact.ToArray()))) .ForMember(d => d.ContactId, opt => opt.MapFrom(s => s._spd_contactid_value)) .ForMember(d => d.LicenceId, opt => opt.MapFrom(s => s._spd_swlnumber_value)) .ForMember(d => d.BizId, opt => opt.MapFrom(s => s._spd_organizationid_value)) @@ -74,5 +76,10 @@ private static (Guid? InviteId, ApplicationInviteStatusEnum? InviteStatus) GetLa } } } + + private static IEnumerable GetPositions(spd_position[] positions) + { + return positions.Select(p => Enum.Parse(DynamicsContextLookupHelpers.LookupPositionKey(p.spd_positionid))).AsEnumerable(); + } } } diff --git a/src/Spd.Utilities.Dynamics/DynamicsContextLookupHelpers.cs b/src/Spd.Utilities.Dynamics/DynamicsContextLookupHelpers.cs index 53a85c6a7..8318aaf99 100644 --- a/src/Spd.Utilities.Dynamics/DynamicsContextLookupHelpers.cs +++ b/src/Spd.Utilities.Dynamics/DynamicsContextLookupHelpers.cs @@ -282,6 +282,11 @@ public static string LookupLicenceCategoryKey(Guid? licenceCategoryId) .Where(s => s.statecode != DynamicsConstants.StateCode_Inactive) .FirstOrDefault(); } + + public static string LookupPositionKey(Guid? positionId) + { + return PositionDictionary.FirstOrDefault(s => s.Value == positionId).Key; + } #endregion public static async Task GetApplicationById(this DynamicsContext context, Guid appId, CancellationToken ct)