private static bool AssignCustomerParts(MappingResult <CreditInquiry> result, CreditInquiry inquiry,
                                                DocumentPageProcessingCompleted processedPage)
        {
            var anyError = false;

            inquiry.Customer.Name = processedPage.ProcessedTextAreas.Single(pta => pta.AreaName == "Wnioskodawca 1 - Imie").ResultStringified;
            if (inquiry.Customer.Name == null)
            {
                anyError = true;
                result.Errors.Add("Nie wprowadzono imienia wnioskodawcy");
            }

            inquiry.Customer.Surname = processedPage.ProcessedTextAreas.Single(pta => pta.AreaName == "Wnioskodawca 1 - Nazwisko").ResultStringified;
            if (inquiry.Customer.Surname == null)
            {
                anyError = true;
                result.Errors.Add("Nie wprowadzono nazwiska wnioskodawcy");
            }

            inquiry.Customer.PESEL = processedPage.ProcessedTextAreas
                                     .Single(pta => pta.AreaName == "Wnioskodawca 1 - PESEL").ResultStringified;

            if (inquiry.Customer.PESEL == null)
            {
                anyError = true;
                result.Errors.Add("Nie wprowadzono nr PESEL wnioskodawcy");
            }
            else if (inquiry.Customer.PESEL.Length < 11)
            {
                anyError = true;
                result.Errors.Add("Nie wprowadzono wszystkich cyfr nr PESEL");
            }
            else
            {
                var peselNumbers = inquiry.Customer.PESEL.Select(num => int.Parse(num.ToString())).ToList();

                int controlSum = 0;

                controlSum += 9 * peselNumbers[0];
                controlSum += 7 * peselNumbers[1];
                controlSum += 3 * peselNumbers[2];
                controlSum += 1 * peselNumbers[3];
                controlSum += 9 * peselNumbers[4];
                controlSum += 7 * peselNumbers[5];
                controlSum += 3 * peselNumbers[6];
                controlSum += 1 * peselNumbers[7];
                controlSum += 9 * peselNumbers[8];
                controlSum += 7 * peselNumbers[9];

                if (controlSum % 10 != peselNumbers[10])
                {
                    anyError = true;
                    result.Errors.Add("Nr PESEL jest nieprawidlowy");
                }
            }

            return(anyError);
        }
Exemplo n.º 2
0
        public async Task MapAndSendDocumentPage(DocumentPageProcessingCompleted page)
        {
            var mappingResult = ExampleMapper.MapToDomainModel(page);

            foreach (var pair in Sockets)
            {
                if (pair.Value.State == WebSocketState.Open)
                {
                    await SendMessageAsync(pair.Value, JsonConvert.SerializeObject(mappingResult));
                }
            }
        }
        public MappingResult <CreditInquiry> MapToDomainModel(DocumentPageProcessingCompleted processedPage)
        {
            var result = new MappingResult <CreditInquiry>();

            result.Scope = "Page";

            var inquiry = new CreditInquiry(processedPage.DocumentId);

            inquiry.Customer = new Customer();
            bool anyError = false;

            var inquiryType = processedPage.ProcessedChoiceAreas
                              .Where(pca => pca.AreaName.StartsWith("Typ wniosku - ") && pca.RecognitionOutput == true)
                              .ToList();

            anyError &= AssignInquiryType(result, inquiry, inquiryType);
            anyError &= AssignCustomerParts(result, inquiry, processedPage);

            result.WasSuccessful = !anyError;
            result.Result        = inquiry;

            return(result);
        }