public async Task <ApplicationView> Handle(PullPartyDataCommand message, CancellationToken cancellationToken)
        {
            var application = await _applicationRepository.GetAsync(message.ApplicationNumber, "involved-parties");

            if (application == null)
            {
                _logger.LogError("Application {applicationNumber} not found for updating data of involved parties.", message.ApplicationNumber);
                return(null);
            }

            for (int i = 0; i < application.InvolvedParties.Count; i++)
            {
                var party = application.InvolvedParties[i];
                if (party.CustomerNumber != null)
                {
                    var partyData = await _partyDataService.GetPartyData(party);

                    if (party.PartyRole == PartyRole.Customer)
                    {
                        application.CustomerName   = partyData.CustomerName;
                        application.CustomerNumber = partyData.CustomerNumber;

                        if (string.IsNullOrEmpty(application.CountryCode) && party != null)
                        {
                            application.CountryCode = party.CountryOfResidence;
                        }
                        if (string.IsNullOrEmpty(application.PrefferedCulture) && party != null)
                        {
                            application.PrefferedCulture = party.PreferredCulture;
                        }
                    }
                    _partyRepository.Update(partyData);
                }
            }

            _applicationRepository.Update(application);
            if (message.AuditLog)
            {
                await _auditClient.WriteLogEntry(AuditLogEntryAction.Update, AuditLogEntryStatus.Success, "involved-parties", application.ApplicationNumber, "Updating data for involved parties in application", new { });
            }
            ApplicationView result   = (ApplicationView)AutoMapper.Mapper.Map(application, typeof(Domain.AggregatesModel.ApplicationAggregate.Application), typeof(ApplicationView));
            bool            resultOk = await _applicationRepository.UnitOfWork.SaveEntitiesAsync();

            if (resultOk)
            {
                return(result);
            }
            else
            {
                _logger.LogError("Updating data of involved parties for application {applicationNumber} has failed.", message.ApplicationNumber);
                return(null);
            }
        }
        private async Task <int> HandleParties(OfferApplication application, InitiateOnlineOfferCommand message)
        {
            // Checking active offers
            string activeStatuses = await _configurationService.GetEffective("offer/active-statuses", "draft,active,approved,accepted");

            List <ApplicationStatus> statusList = null;

            if (!string.IsNullOrEmpty(activeStatuses))
            {
                statusList = EnumUtils.GetEnumPropertiesForListString <ApplicationStatus>(activeStatuses);
            }
            var   rolesList = EnumUtils.GetEnumPropertiesForListString <PartyRole>("customer");
            Party party;

            int activeOffers;

            if (string.IsNullOrEmpty(message.CustomerNumber))
            {
                if (string.IsNullOrEmpty(message.EmailAddress))
                {
                    activeOffers = 0;
                }
                else
                {
                    activeOffers = _applicationRepository.CheckExistingOffersForProspect(message.Username, message.EmailAddress, statusList, rolesList).Count;
                }
                party = new IndividualParty
                {
                    GivenName                = message.GivenName,
                    Surname                  = message.Surname,
                    ParentName               = message.ParentName,
                    CustomerName             = message.GivenName + " " + message.Surname,
                    IdentificationNumberKind = message.IdentificationNumberKind,
                    IdentificationNumber     = message.IdentificationNumber,
                    EmailAddress             = message.EmailAddress,
                    MobilePhone              = message.MobilePhone,
                    Gender    = Gender.Unknown,
                    PartyRole = PartyRole.Customer,
                    Username  = message.Username
                };

                party.LegalAddress = new PostalAddress
                {
                    Coordinates = new Coordinates()
                };
                party.ContactAddress = new PostalAddress
                {
                    Coordinates = new Coordinates()
                };
                application.InvolvedParties = new List <Party> {
                    party
                };
                _logger.LogInformation("New customer: {givenName} {surname} ({emailAddress})", message.GivenName, message.Surname, message.EmailAddress);
            }
            else
            {
                activeOffers = _applicationRepository.CheckExistingOffersForCustomer(message.CustomerNumber, statusList, rolesList).Count;
                if (message.PartyKind == PartyKind.Organization)
                {
                    party = new OrganizationParty
                    {
                        CustomerNumber = message.CustomerNumber,
                        EmailAddress   = message.EmailAddress,
                        PartyKind      = PartyKind.Organization
                    };
                }
                else
                {
                    party = new IndividualParty
                    {
                        CustomerNumber = message.CustomerNumber,
                        EmailAddress   = message.EmailAddress
                    };
                }

                var partyData = await _partyDataService.GetPartyData(party);

                string defaultOrganizationUnit = await _configurationService.GetEffective("offer/default-organization-unit", null);

                if (!string.IsNullOrEmpty(message.AgentOrganizationUnit))
                {
                    application.OrganizationUnitCode = message.AgentOrganizationUnit;
                }
                else
                {
                    application.OrganizationUnitCode = partyData.OrganizationUnitCode ?? defaultOrganizationUnit;
                }

                application.InvolvedParties = new List <Party> {
                    party
                };

                //if (partyData is OrganizationParty orgParty && orgParty.Relationships.Count() > 0)
                //{
                //    List<Relationships> listRelationships = orgParty.Relationships;
                //    foreach (var item in listRelationships)
                //    {
                //        Party customerRepresentative;
                //        if (item.ToParty.Kind == PartyKind.Individual)
                //        {
                //            customerRepresentative = new IndividualParty
                //            {
                //                CustomerNumber = item.ToParty.Number.ToString(),
                //                PartyRole = PartyRole.AuthorizedPerson
                //            };
                //        }
                //        else
                //        {
                //            customerRepresentative = new OrganizationParty
                //            {
                //                CustomerNumber = item.ToParty.Number.ToString(),
                //                PartyRole = PartyRole.AuthorizedPerson
                //            };
                //        }

                //        var customerRelationship = await _partyDataService.GetPartyData(customerRepresentative);
                //        application.InvolvedParties.Add(customerRepresentative);
                //    }
                //}

                if (party.PartyRole == PartyRole.Customer)
                {
                    application.CustomerName   = partyData.CustomerName;
                    application.CustomerNumber = partyData.CustomerNumber;
                    party.EmailAddress         = partyData.EmailAddress;


                    if (string.IsNullOrEmpty(application.CountryCode) && party != null)
                    {
                        application.CountryCode = party.CountryOfResidence;
                    }
                    if (string.IsNullOrEmpty(application.PrefferedCulture) && party != null)
                    {
                        application.PrefferedCulture = party.PreferredCulture;
                    }
                }

                _logger.LogInformation("Existing customer: {customerNumber} ({emailAddress})", party.CustomerNumber, party.EmailAddress);
            }

            return(activeOffers);
        }
Esempio n. 3
0
        public async Task <ExposureInfo> CalculateExposureRelatedGroups(ExposureInfo exposureInfo, string customerNumber, RetrieveCurrentExposureCommand message, Party involvedParty, List <string> listOfCalcParties)
        {
            var exposureRelatedGroups = _configurationService.GetEffective <List <string> >("offer/exposure-related-groups", "ownership").Result;

            if (!listOfCalcParties.Contains(involvedParty.CustomerNumber))
            {
                listOfCalcParties.Add(involvedParty.CustomerNumber);

                if (involvedParty.PartyKind == PartyKind.Organization)
                {
                    var org = (OrganizationParty)involvedParty;

                    var relatedParties = org.Relationships != null?org.Relationships.Where(r => exposureRelatedGroups.Contains(r.Kind) && !listOfCalcParties.Contains(r.ToParty.Number)).ToList() : null;

                    await GetExposureIndividual(exposureInfo, org.CustomerNumber, org.CustomerName, message);

                    if (relatedParties != null)
                    {
                        foreach (var relatedParty in relatedParties)
                        {
                            if (!listOfCalcParties.Contains(relatedParty.ToParty.Number))
                            {
                                // listOfCalcParties.Add(relatedParty.ToParty.Number);
                                // call arrangement api to retrieve credit arrangements where customer plays "customer", "guarantor", or "co-debtor" role
                                try
                                {
                                    if (relatedParty.ToParty.Kind == PartyKind.Organization)
                                    {
                                        Party party = new OrganizationParty {
                                            CustomerNumber = relatedParty.ToParty.Number, PartyKind = relatedParty.ToParty.Kind
                                        };
                                        var orgparty = await _masterPartyDataService.GetPartyData(party);

                                        await CalculateExposureRelatedGroups(exposureInfo, relatedParty.ToParty.Number, message, orgparty, listOfCalcParties);
                                    }
                                    else
                                    {
                                        Party party = new IndividualParty {
                                            CustomerNumber = relatedParty.ToParty.Number, PartyKind = relatedParty.ToParty.Kind
                                        };
                                        var orgparty = await _masterPartyDataService.GetPartyData(party);

                                        await CalculateExposureRelatedGroups(exposureInfo, relatedParty.ToParty.Number, message, orgparty, listOfCalcParties);
                                    }
                                }
                                catch (Exception e)
                                {
                                    _logger.LogError(e, "An error occurred while retrieving current exposure for application number {applicationNumber}", message.ApplicationNumber);
                                    // return new CommandStatus { CommandResult = StandardCommandResult.INTERNAL_ERROR, Exception = e };
                                }
                            }
                        }
                    }
                }
                else
                {
                    var org = (IndividualParty)involvedParty;

                    var relatedParties = org.Relationships != null?org.Relationships.Where(r => exposureRelatedGroups.Contains(r.Kind) && !listOfCalcParties.Contains(r.ToParty.Number)).ToList() : null;

                    await GetExposureIndividual(exposureInfo, org.CustomerNumber, org.CustomerName, message);

                    if (relatedParties != null)
                    {
                        foreach (var relatedParty in relatedParties)
                        {
                            if (!listOfCalcParties.Contains(relatedParty.ToParty.Number))
                            {
                                // listOfCalcParties.Add(relatedParty.ToParty.Number);
                                // call arrangement api to retrieve credit arrangements where customer plays "customer", "guarantor", or "co-debtor" role
                                try
                                {
                                    if (relatedParty.ToParty.Kind == PartyKind.Organization)
                                    {
                                        Party party = new OrganizationParty {
                                            CustomerNumber = relatedParty.ToParty.Number, PartyKind = relatedParty.ToParty.Kind
                                        };
                                        var orgparty = await _masterPartyDataService.GetPartyData(party);

                                        await CalculateExposureRelatedGroups(exposureInfo, relatedParty.ToParty.Number, message, orgparty, listOfCalcParties);
                                    }
                                    else
                                    {
                                        Party party = new IndividualParty {
                                            CustomerNumber = relatedParty.ToParty.Number, PartyKind = relatedParty.ToParty.Kind
                                        };
                                        var orgparty = await _masterPartyDataService.GetPartyData(party);

                                        await CalculateExposureRelatedGroups(exposureInfo, relatedParty.ToParty.Number, message, orgparty, listOfCalcParties);
                                    }
                                }
                                catch (Exception e)
                                {
                                    _logger.LogError(e, "An error occurred while retrieving current exposure for application number {applicationNumber}", message.ApplicationNumber);
                                    // return new CommandStatus { CommandResult = StandardCommandResult.INTERNAL_ERROR, Exception = e };
                                }
                            }
                        }
                    }
                }
            }
            return(exposureInfo);
        }
Esempio n. 4
0
        public async Task <List <OfferApplication> > GetAppsForExposureRelatedGroups(string customerNumber, Party involvedParty, List <OfferApplication> otherApplications, List <ApplicationStatus> statusesList, List <PartyRole> rolesList, List <string> listOfCalcParties)
        {
            var exposureRelatedGroups = _configurationService.GetEffective <List <string> >("offer/exposure-related-groups", "ownership").Result;

            if (!listOfCalcParties.Contains(involvedParty.CustomerNumber))
            {
                listOfCalcParties.Add(involvedParty.CustomerNumber);

                if (involvedParty.PartyKind == PartyKind.Organization)
                {
                    var org = (OrganizationParty)involvedParty;

                    var relatedParties = org.Relationships != null?org.Relationships.Where(r => exposureRelatedGroups.Contains(r.Kind) && !listOfCalcParties.Contains(r.ToParty.Number)).ToList() : null;

                    otherApplications.AddRange(_applicationRepository.CheckExistingOffersForCustomer(customerNumber, statusesList, rolesList));
                    if (relatedParties != null)
                    {
                        foreach (var relatedParty in relatedParties)
                        {
                            if (!listOfCalcParties.Contains(relatedParty.ToParty.Number))
                            {
                                // listOfCalcParties.Add(relatedParty.ToParty.Number);
                                if (relatedParty.ToParty.Kind == PartyKind.Individual)
                                {
                                    //existing customer
                                    Party partyorg = new IndividualParty {
                                        CustomerNumber = relatedParty.ToParty.Number, PartyKind = relatedParty.ToParty.Kind
                                    };
                                    var inparty = await _masterPartyDataService.GetPartyData(partyorg);

                                    await GetAppsForExposureRelatedGroups(relatedParty.ToParty.Number, inparty, otherApplications, statusesList, rolesList, listOfCalcParties);

                                    // otherApplications.AddRange(_applicationRepository.CheckExistingOffersForCustomer(relatedParty.ToParty.Number, statusesList, rolesList));
                                }
                                else
                                {
                                    Party partyorg = new OrganizationParty {
                                        CustomerNumber = relatedParty.ToParty.Number, PartyKind = relatedParty.ToParty.Kind
                                    };
                                    var orgparty = await _masterPartyDataService.GetPartyData(partyorg);

                                    await GetAppsForExposureRelatedGroups(relatedParty.ToParty.Number, orgparty, otherApplications, statusesList, rolesList, listOfCalcParties);
                                }
                            }
                        }
                    }
                }
                else
                {
                    var org = (IndividualParty)involvedParty;

                    var relatedParties = org.Relationships != null?org.Relationships.Where(r => exposureRelatedGroups.Contains(r.Kind) && !listOfCalcParties.Contains(r.ToParty.Number)).ToList() : null;

                    otherApplications.AddRange(_applicationRepository.CheckExistingOffersForCustomer(customerNumber, statusesList, rolesList));
                    if (relatedParties != null)
                    {
                        foreach (var relatedParty in relatedParties)
                        {
                            if (!listOfCalcParties.Contains(relatedParty.ToParty.Number))
                            {
                                // listOfCalcParties.Add(relatedParty.ToParty.Number);
                                if (relatedParty.ToParty.Kind == PartyKind.Individual)
                                {
                                    Party partyin = new IndividualParty {
                                        CustomerNumber = relatedParty.ToParty.Number, PartyKind = relatedParty.ToParty.Kind
                                    };
                                    var inparty = await _masterPartyDataService.GetPartyData(partyin);

                                    await GetAppsForExposureRelatedGroups(relatedParty.ToParty.Number, inparty, otherApplications, statusesList, rolesList, listOfCalcParties);

                                    // otherApplications.AddRange(_applicationRepository.CheckExistingOffersForCustomer(relatedParty.ToParty.Number, statusesList, rolesList));
                                }
                                else
                                {
                                    Party partyorg = new OrganizationParty {
                                        CustomerNumber = relatedParty.ToParty.Number, PartyKind = relatedParty.ToParty.Kind
                                    };
                                    var orgparty = await _masterPartyDataService.GetPartyData(partyorg);

                                    await GetAppsForExposureRelatedGroups(relatedParty.ToParty.Number, orgparty, otherApplications, statusesList, rolesList, listOfCalcParties);
                                }
                            }
                        }
                    }
                }
            }
            return(otherApplications);
        }