/* this avoids multiple policies with same endorsement numbers to be created */
var policies = _policyRepository.GetAll();
var q = from pol in policies
where pol.Id == policy.Id
let policyNo = pol.PolicyNo
from p in policies
where p.PolicyNo == policyNo
&& p.Id != policy.Id
&& p.ProposalStatus == ProposalStatus.Proposal
&& p.EndorsementNo == policy.EndorsementNo
group p by new
{
p.EndorsementNo,
p.Id
}
into grouping
select new
{
grouping.Key.Id
};
var policiesToIgnore = q.ToListAsync().Result;
foreach (var policyToIgnore in policiesToIgnore)
{
var policyToBePassive = await _policyRepository.GetAsync(policyToIgnore.Id);
policyToBePassive.PolicyStatus = PolicyStatusEnum.Passive;
await _policyRepository.UpdateAsync(policyToBePassive);
}