Beispiel #1
0
        private async Task AddEnglishFractionsToPayeSchemes(long accountId, List <PayeView> payeSchemes)
        {
            var englishFractions = (await _englishFractionRepository.GetCurrentFractionForSchemes(
                                        accountId,
                                        payeSchemes.Select(x => x.Ref))).Where(x => x != null).ToList();

            foreach (var scheme in payeSchemes)
            {
                scheme.EnglishFraction = englishFractions.FirstOrDefault(x => x.EmpRef == scheme.Ref);
            }
        }
Beispiel #2
0
        public async Task <GetAccountPayeSchemesResponse> Handle(GetAccountPayeSchemesQuery message)
        {
            var validationResult = await _validator.ValidateAsync(message);

            if (!validationResult.IsValid())
            {
                throw new InvalidRequestException(validationResult.ValidationDictionary);
            }

            if (validationResult.IsUnauthorized)
            {
                throw new UnauthorizedAccessException();
            }

            var accountId = _hashingService.DecodeValue(message.HashedAccountId);

            var payeSchemes = await _payeRepository.GetPayeSchemesByAccountId(accountId);

            if (payeSchemes.Count == 0)
            {
                return(new GetAccountPayeSchemesResponse
                {
                    PayeSchemes = payeSchemes
                });
            }

            var englishFractions = (await _englishFractionRepository.GetCurrentFractionForSchemes(accountId, payeSchemes.Select(x => x.Ref))).Where(x => x != null).ToList();

            foreach (var scheme in payeSchemes)
            {
                scheme.EnglishFraction = englishFractions.FirstOrDefault(x => x.EmpRef == scheme.Ref);
            }

            return(new GetAccountPayeSchemesResponse
            {
                PayeSchemes = payeSchemes
            });
        }