private async Task <bool> UpdateProspectOffers(UpdateCustomerNumberCommand message)
        {
            _logger.LogInformation("Updating active prospect offers"); // with customer number {customerNumber}", message.CustomerNumber);
            string activeStatuses = await _configurationService.GetEffective("offer/active-statuses", "draft");

            List <ApplicationStatus> activeStatusList = EnumUtils.GetEnumPropertiesForListString <ApplicationStatus>(activeStatuses);
            var applications = _applicationRepository.GetProspectOffers(message.Username, activeStatusList);

            foreach (Domain.AggregatesModel.ApplicationAggregate.Application app in applications)
            {
                if (string.IsNullOrEmpty(app.CustomerNumber))
                {
                    app.CustomerNumber = message.CustomerNumber;
                    _applicationRepository.Update(app);
                    _logger.LogInformation("Customer number in application {applicationNumber} updated to {customerNumber}.", app.ApplicationNumber, message.CustomerNumber);
                }
                else
                {
                    _logger.LogWarning("Customer number in aplication {aplicationNumber} already exist! Found: {oldCustomerNumber}, should be: {customerNumber}",
                                       app.ApplicationNumber, app.CustomerNumber, message.CustomerNumber);
                }

                var party = app.InvolvedParties?.Where(x => x.PartyRole == PartyRole.Customer).FirstOrDefault();
                if (party != null)
                {
                    IndividualParty customer = (IndividualParty)party;
                    if (string.IsNullOrEmpty(customer.CustomerNumber))
                    {
                        customer.CustomerNumber = message.CustomerNumber;
                        _partyRepository.Update(customer);
                    }
                    else
                    {
                        _logger.LogWarning("Customer number for involved party in aplication {aplicationNumber} already exist! Found: {oldCustomerNumber}, should be: {customerNumber}",
                                           app.ApplicationNumber, customer.CustomerNumber, message.CustomerNumber);
                    }
                }
                if (message.AuditLog)
                {
                    await _auditClient.WriteLogEntry(AuditLogEntryAction.Update, AuditLogEntryStatus.Success, "customer-number", app.ApplicationNumber, "Updated customer number " + party.CustomerNumber, new { });
                }
            }

            return(await _applicationRepository.UnitOfWork.SaveEntitiesAsync());
        }
Esempio n. 2
0
        public void Party_should_be_constructed_in_waitingForActive_state()
        {
            var party = new IndividualParty(new PartyId(1), "X", "Y", "10", new FakePublisher());

            Assert.IsType <WaitingForActivationState>(party.State);
        }
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);
        }
        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. 5
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);
        }