Exemplo n.º 1
0
        private void ReadDataFile(string dataFilepath, string schemaFilepath)
        {
            XmlSerializer contractSerializer = new XmlSerializer(typeof(Batch));

            /* Define XML Reader Settings */
            XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();

            xmlReaderSettings.ConformanceLevel = ConformanceLevel.Document;
            xmlReaderSettings.ValidationType   = ValidationType.Schema;
            xmlReaderSettings.Schemas.Add(DEFAULT_SCHEMA, schemaFilepath);

            using (XmlReader xmlReader = XmlReader.Create(dataFilepath, xmlReaderSettings))
            {
                xmlReader.MoveToContent();

                while (xmlReader.ReadToFollowing("Contract"))
                {
                    BatchContract batchCobtract = (BatchContract)contractSerializer.Deserialize(xmlReader.ReadSubtree());

                    Console.WriteLine($"Contract {batchCobtract.ContractCode} loaded");

                    Contract contract = ConvertBatchContractToContract(batchCobtract);

                    Console.WriteLine($"Contract {batchCobtract.ContractCode} mapped to object");

                    PrintContract(contract);

                    SaveContractToDb(contract);

                    Console.WriteLine($"Contract {batchCobtract.ContractCode} saved into DB");
                }
            }
        }
Exemplo n.º 2
0
        private Contract ConvertBatchContractToContract(BatchContract batchContract)
        {
            /* Map BatchContract to Contract */
            Contract contract = new Contract()
            {
                contractCode = batchContract.ContractCode,

                /* Map BatchContractContractData to Contract */
                phaseOfContract = batchContract.ContractData.PhaseOfContract == ContractPhaseOfContract.Open ? "Open" : "Close",
                originalAmount  = new Amount()
                {
                    value = batchContract.ContractData.OriginalAmount.Value, currency = batchContract.ContractData.OriginalAmount.Currency.ToString()
                },
                installmentAmount = new Amount()
                {
                    value = batchContract.ContractData.InstallmentAmount.Value, currency = batchContract.ContractData.InstallmentAmount.Currency.ToString()
                },
                currentBalance = new Amount()
                {
                    value = batchContract.ContractData.CurrentBalance.Value, currency = batchContract.ContractData.CurrentBalance.Currency.ToString()
                },
                overdueBalance = new Amount()
                {
                    value = batchContract.ContractData.OverdueBalance.Value, currency = batchContract.ContractData.OverdueBalance.Currency.ToString()
                },
                dateOfLastPayment = batchContract.ContractData.DateOfLastPayment,
                nextPaymentDate   = batchContract.ContractData.NextPaymentDate,
                dateAccountOpened = batchContract.ContractData.DateAccountOpened,
                realEndDate       = batchContract.ContractData.RealEndDate
            };

            /* Map BatchContractIndividuals to Individuals and add them into Contract */
            contract.individuals = new List <Individual>();
            foreach (BatchContractIndividual batchIndividual in batchContract.Individual)
            {
                Individual individual = new Individual()
                {
                    CustomerCode = batchIndividual.CustomerCode,
                    contractCode = contract.contractCode,
                    FirstName    = batchIndividual.FirstName,
                    LastName     = batchIndividual.LastName,

                    Gender      = batchIndividual.Gender.ToString(),
                    DateOfBirth = batchIndividual.DateOfBirth,
                };

                IdentificationNumber identNo = new IdentificationNumber()
                {
                    nationalID = batchIndividual.IdentificationNumbers.NationalID, individual = individual
                };
                individual.identificationNumbers = new List <IdentificationNumber>();
                individual.identificationNumbers.Add(identNo);

                contract.individuals.Add(individual);
            }

            /* Map BatchContractSubjectRoles to SubjectRoles and add them into Contract */
            contract.subjectRoles = new List <SubjectRole>();
            foreach (BatchContractSubjectRole batchSubjectRole in batchContract.SubjectRole)
            {
                SubjectRole subjectRole = new SubjectRole()
                {
                    contractCode   = contract.contractCode,
                    customerCode   = batchSubjectRole.CustomerCode,
                    roleOfCustomer = batchSubjectRole.RoleOfCustomer.ToString()
                };

                if (batchSubjectRole.GuaranteeAmount != null)
                {
                    subjectRole.guaranteeAmount = new Amount(amount: batchSubjectRole.GuaranteeAmount.Value, currency: batchSubjectRole.GuaranteeAmount.Currency.ToString());
                }
                else
                {
                    subjectRole.guaranteeAmount = new Amount()
                    {
                        value = 0, currency = ""
                    };
                }

                contract.subjectRoles.Add(subjectRole);
            }

            return(contract);
        }