public Task <GetPolicyDetailsResponseDto> Handle(GetPolicyDetailsRequestDto request, CancellationToken cancellationToken)
        {
            //TODO: request validation

            var policy = dbContext.Policy.Include(x => x.PolicyVersions).ThenInclude(x => x.PolicyHolder).FirstOrDefault(x => x.PolicyNumber == request.PolicyNumber);

            if (policy == null)
            {
                throw new PolicyNotFoundException(request.PolicyNumber);
            }

            var policyVersion = policy.GetPolicyVersion(request.PolicyStartDate);

            if (policyVersion == null)
            {
                //TODO: maybe move this to GetPolicyVersion method in Policy domain ??
                throw new PolicyVersionNotFoundException(policy.PolicyNumber, request.PolicyStartDate);
            }

            var response = new GetPolicyDetailsResponseDto()
            {
                PolicyVersion = PolicyVersionMapper.MapPolicyVersionToPolicyVersionDto(policyVersion)
            };

            return(Task.FromResult(response));
        }
Example #2
0
        public Task <TerminatePolicyResponseDto> Handle(TerminatePolicyRequestDto request, CancellationToken cancellationToken)
        {
            //TODO: validate request

            var policy        = dbContext.Policy.Include(x => x.PolicyVersions).ThenInclude(x => x.PolicyHolder).FirstOrDefault(x => x.PolicyNumber == request.PolicyNumber);
            var policyVersion = policy.Terminate(request.TerminationDate);

            dbContext.Policy.Update(policy);
            dbContext.SaveChanges();

            var response = new TerminatePolicyResponseDto()
            {
                TerminatedPolicyVersion = PolicyVersionMapper.MapPolicyVersionToPolicyVersionDto(policyVersion)
            };

            return(Task.FromResult(response));
        }