Example #1
0
        /// <summary>
        /// Tests the connections to CCM SOAP and REST services.
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="facility"></param>
        /// <param name="soapServiceUrl"></param>
        /// <param name="restServiceUrl"></param>
        /// <returns></returns>
        public BaseResult TestConnections(string userName, string password, string facility, string soapServiceUrl, string restServiceUrl)
        {
            var result = new BaseResult();

            using (var tr = new Tracer("LMS.Connector.CCM.CCMOrigination.TestConnections"))
            {
                try
                {
                    var soapConnectionResult = TestSoapConnection(soapServiceUrl, userName, password, facility);
                    result.AppendResult(soapConnectionResult);
                    tr.Log($"SOAP connection result = {soapConnectionResult.Result}");

                    var restConnectionResult = TestRestConnection(restServiceUrl, userName, password, facility);
                    result.AppendResult(restConnectionResult);
                    tr.Log($"REST connection result = {restConnectionResult.Result}");

                    result.Result = soapConnectionResult.Result && restConnectionResult.Result;
                }
                catch (Exception ex)
                {
                    result.Result      = false;
                    result.ExceptionId = Utility.LogError(ex, "LMS.Connector.CCM.CCMOrigination.TestConnections");
                    result.AddMessage(MessageType.Error, ex.Message);
                    tr.LogException(ex);
                }
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Creates a card for the primary or joint applicant using AddCard behavior call. Then sets the applicant's card number in LMS.
        /// </summary>
        /// <param name="strategy"></param>
        /// <param name="primaryOrJointApplicant"></param>
        /// <returns></returns>
        public BaseResult AddCard(ClientStrategy strategy, Applicant primaryOrJointApplicant)
        {
            var result    = new BaseResult();
            var lmsPerson = new LmsPerson()
            {
                Applicant = primaryOrJointApplicant
            };
            string cardNumber = string.Empty;

            var addCardStrategyResult = strategy.AddCard(lmsPerson, out cardNumber);

            result.AppendResult(addCardStrategyResult);

            if (addCardStrategyResult.Result)
            {
                // Store the CCM AccountNumber received from the response to the primary or joint applicant CardNumber field
                var applicant = _app.Applicants.SingleOrDefault(a => a.ApplicantId == primaryOrJointApplicant.ApplicantId);
                applicant.CardNumber = cardNumber;
            }
            else
            {
                var applicantName = (primaryOrJointApplicant.IsOrganization) ? primaryOrJointApplicant.OrganizationName : primaryOrJointApplicant.FullName;
                result.AddMessage(MessageType.Warning, $"An error occured creating the plastic card. The card will not be created on CCM for {applicantName}.");
                result.Result = true;
            }

            return(result);
        }
Example #3
0
        /// <summary>
        /// Adds a person to CCM using AddPerson behavior call.
        /// </summary>
        /// <param name="strategy"></param>
        /// <param name="applicant"></param>
        /// <returns></returns>
        public BaseResult AddPerson(ClientStrategy strategy, Applicant applicant)
        {
            var result    = new BaseResult();
            var lmsPerson = new LmsPerson()
            {
                Applicant = applicant
            };

            var addPersonStrategyResult = strategy.AddPerson(lmsPerson);

            result.AppendResult(addPersonStrategyResult);

            if (!addPersonStrategyResult.Result)
            {
                if (applicant.ApplicantTypeId.GetValueOrDefault() == (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicantType.Joint)
                {
                    string applicantTypeName = LookupCodes.ApplicantType.Joint;
                    result.AddMessage(MessageType.Warning, $"An error occured adding the {applicantTypeName} Applicant Type. {applicant.FullName} will not be added to CCM.");
                }
                else
                {
                    result.AddError("An error occurred creating the credit card record for the loan. The credit card will not be created in CCM.");

                    return(result);
                }
            }

            return(result);
        }
Example #4
0
        /// <summary>
        /// Creates a card for the authorized user using AddCard behavior call. Then sets the authorized user's card number in LMS.
        /// </summary>
        /// <param name="strategy"></param>
        /// <param name="authorizedUser"></param>
        /// <returns></returns>
        public BaseResult AddCard(ClientStrategy strategy, AuthorizedUser authorizedUser)
        {
            var result    = new BaseResult();
            var lmsPerson = new LmsPerson()
            {
                AuthorizedUser = authorizedUser
            };
            string cardNumber = string.Empty;

            var addCardResult = strategy.AddCard(lmsPerson, out cardNumber);

            result.AppendResult(addCardResult);

            if (addCardResult.Result)
            {
                //Store the CCM AccountNumber received from the response to the authorized user CardNumber field
                var authUser = _app.AuthorizedUsers.SingleOrDefault(a => a.AuthorizedUserId == authorizedUser.AuthorizedUserId);
                authUser.CardNumber = cardNumber;
            }
            else
            {
                result.AddMessage(MessageType.Warning, $"An error occured creating the plastic card. The card will not be created on CCM for {authorizedUser.FirstName} {authorizedUser.LastName}.");
                result.Result = true;
            }

            return(result);
        }
Example #5
0
        /// <summary>
        /// Tests the connection to CCM REST service using TestConnection behavior call.
        /// </summary>
        /// <param name="restServiceUrl"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="facility"></param>
        /// <returns></returns>
        public BaseResult TestRestConnection(string restServiceUrl, string userName, string password, string facility)
        {
            var result = new BaseResult();

            var restConnectionResult = _restStrategy.TestConnection(restServiceUrl, userName, password, facility);

            result.AppendResult(restConnectionResult);

            return(result);
        }
Example #6
0
        /// <summary>
        /// Makes an Inquiry behavior call to determine if a person exists in CCM, and also gets RelationshipInfo objects.
        /// </summary>
        /// <param name="strategy"></param>
        /// <param name="personNumber"></param>
        /// <param name="errorMessage"></param>
        /// <param name="relationshipInfos"></param>
        /// <returns></returns>
        public BaseResult MakeInquiry(ClientStrategy strategy, string personNumber, out string errorMessage, out IList <RelationshipInfo> relationshipInfos)
        {
            var result = new BaseResult();

            var inquiryResult = strategy.Inquiry(personNumber, out errorMessage, out relationshipInfos);

            result.AppendResult(inquiryResult);

            if (!inquiryResult.Result)
            {
                result.AddMessage(MessageType.Warning, $"An error occured making Inquiry for personNumber {personNumber}.");
            }

            return(result);
        }
Example #7
0
        /// <summary>
        /// Adds a party relationship for a joint applicant in CCM using AddAccountPartyRelationship behavior call.
        /// </summary>
        /// <param name="strategy"></param>
        /// <param name="applicant"></param>
        /// <returns></returns>
        public BaseResult AddAccountPartyRelationship(ClientStrategy strategy, Applicant applicant)
        {
            var result = new BaseResult();
            var addAccountPartyRelationshipStrategyResult = strategy.AddAccountPartyRelationship(applicant);

            result.AppendResult(addAccountPartyRelationshipStrategyResult);

            if (!addAccountPartyRelationshipStrategyResult.Result)
            {
                var jointApplicantName = (applicant.IsOrganization) ? applicant.OrganizationName : applicant.FullName;
                result.AddMessage(MessageType.Warning, $"An error occured adding the Joint. {jointApplicantName} will not be added on CCM.");
            }

            return(result);
        }
Example #8
0
        /// <summary>
        /// Updates the account of a primary applicant in CCM using UpdateAccount behavior call.
        /// </summary>
        /// <param name="strategy"></param>
        /// <param name="applicant"></param>
        /// <returns></returns>
        public BaseResult UpdateAccount(ClientStrategy strategy, Applicant applicant)
        {
            var result = new BaseResult();

            var updateAccountResult = strategy.UpdateAccount(applicant);

            result.AppendResult(updateAccountResult);

            if (!result.Result)
            {
                result.AddError("An error occured increasing the line of credit. The update will not be reflected in CCM.");
            }

            return(result);
        }
Example #9
0
        /// <summary>
        /// Checks for required fields prior to sending calls to the CCM service.
        /// </summary>
        /// <param name="userToken"></param>
        /// <param name="app"></param>
        /// <returns></returns>
        public BaseResult DisbursementValidation(string userToken, ref Application app)
        {
            var result = new BaseResult();

            _app       = app;
            _userToken = userToken;

            using (var tr = new Tracer("LMS.Connector.CCM.Service.Api.DisbursementValidation"))
            {
                var ccm = new CCMValidation(app, userToken);

                result.AppendResult(ccm.DisbursementValidation());

                tr.Log($"LMS.Connector.CCM.Service.Api.DisbursementValidation result => {result.Result}");
            }

            return(result);
        }
Example #10
0
        /// <summary>
        /// Adds an authorized user to CCM using AddPerson behavior call.
        /// </summary>
        /// <param name="strategy"></param>
        /// <param name="authorizedUser"></param>
        /// <returns></returns>
        public BaseResult AddAuthorizedUser(ClientStrategy strategy, AuthorizedUser authorizedUser)
        {
            var result    = new BaseResult();
            var lmsPerson = new LmsPerson()
            {
                AuthorizedUser = authorizedUser
            };

            var addAuthorizedUserStrategyResult = strategy.AddPerson(lmsPerson);

            result.AppendResult(addAuthorizedUserStrategyResult);

            if (!addAuthorizedUserStrategyResult.Result)
            {
                result.AddMessage(MessageType.Warning, $"An error occured adding the AUTHORIZED USER. {authorizedUser.FirstName} {authorizedUser.LastName} will not be added to CCM.");
            }

            return(result);
        }
Example #11
0
        /// <summary>
        /// Creates an account in CCM for the primary applicant using AddAccount behavior call. Then sets the applicant's account number in LMS.
        /// </summary>
        /// <param name="strategy"></param>
        /// <param name="applicant"></param>
        /// <returns></returns>
        public BaseResult AddAccount(ClientStrategy strategy, Applicant applicant)
        {
            var    result        = new BaseResult();
            string accountNumber = string.Empty;

            var addAccountStrategyResult = strategy.AddAccount(applicant, out accountNumber);

            result.AppendResult(addAccountStrategyResult);

            if (addAccountStrategyResult.Result)
            {
                // Store the CCM AccountNumber received from the response to the application CreditCardNumber field
                _app.CreditCardNumber = accountNumber;
            }
            else
            {
                result.AddError("An error occurred creating the credit card record for the loan. The credit card will not be created in CCM.");
            }

            return(result);
        }
Example #12
0
        /// <summary>
        /// Process for disbursing an application that is an Add On.
        /// </summary>
        /// <param name="primaryApplicant"></param>
        /// <param name="jointGuarantorApplicants"></param>
        /// <returns></returns>
        public BaseResult DisburseAddOn(Applicant primaryApplicant, IEnumerable <Applicant> jointGuarantorApplicants)
        {
            var result = new BaseResult();

            using (var tr = new Tracer("LMS.Connector.CCM.CCMOrigination.DisburseAddOn"))
            {
                // Joint or Guarantor applicants
                if (jointGuarantorApplicants?.Any() == true)
                {
                    tr.Log($"Number of joint or guarantor applicants in ApplicationId {_app.ApplicationId} => {jointGuarantorApplicants.Count()}");

                    foreach (var jointGuarantorApplicant in jointGuarantorApplicants)
                    {
                        /*********************
                         * Call AddPerson/AddOrganization on this joint or guarantor applicant (person or organization).
                         */
                        tr.Log($"Adding ApplicantId {jointGuarantorApplicant.ApplicantId} as a person or organization in CCM");
                        tr.Log($"ApplicantId {jointGuarantorApplicant.ApplicantId} is ApplicantTypeId {jointGuarantorApplicant.ApplicantTypeId}");

                        if (!jointGuarantorApplicant.IsOrganization)
                        {
                            // Add the person applicant to CCM
                            var addPersonResult = _ccm.AddPerson(_soapStrategy, jointGuarantorApplicant);
                            result.AppendResult(addPersonResult);
                            tr.Log($"AddPerson result for ApplicantId {jointGuarantorApplicant.ApplicantId} => {addPersonResult.Result}");
                        }
                        else
                        {
                            // Guarantors cannot be organizations
                            if (jointGuarantorApplicant.ApplicantTypeId != (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicantType.Guarantor)
                            {
                                var jointApplicant = jointGuarantorApplicant;

                                // Add the organization applicant to CCM
                                var addOrganizationResult = _ccm.AddOrganization(_soapStrategy, jointApplicant);
                                result.AppendResult(addOrganizationResult);
                                tr.Log($"AddOrganization result for ApplicantId {jointApplicant.ApplicantId} => {addOrganizationResult.Result}");
                            }
                        }
                    }
                }
                else
                {
                    /*
                     * No joint or guarantor applicants in application
                     */
                    tr.Log("There are no joint or guarantor applicants in the application");
                }

                // Authorized users
                if (_app.AuthorizedUsers?.Any() == true)
                {
                    tr.Log($"Number of authorized users in ApplicationId {_app.ApplicationId} => {_app.AuthorizedUsers.Count}");

                    foreach (var authorizedUser in _app.AuthorizedUsers)
                    {
                        /*********************
                         * Call AddPerson passing this authorized user.
                         */
                        tr.Log($"Adding AuthorizedUserId {authorizedUser.AuthorizedUserId} as a person in CCM");

                        // Add the authorized user to CCM
                        var addAuthorizedUserResult = _ccm.AddAuthorizedUser(_soapStrategy, authorizedUser);
                        result.AppendResult(addAuthorizedUserResult);
                        tr.Log($"AddAuthorizedUser result for AuthorizedUserId {authorizedUser.AuthorizedUserId} => {addAuthorizedUserResult.Result}");
                    }
                }
                else
                {
                    /*
                     * No authorized users in application
                     */
                    tr.Log("There are no authorized users in the application");
                }

                /*********************
                 * Update Account to modify the credit limit of primary applicant.
                 */
                tr.Log($"Calling UpdateAccount for ApplicantId {primaryApplicant.ApplicantId}");

                // Make service call to Update Account to update the credit limit of the primary applicant
                var updateAccountResult = _ccm.UpdateAccount(_soapStrategy, primaryApplicant);
                result.AppendResult(updateAccountResult);
                tr.Log($"UpdateAccount result for ApplicantId {primaryApplicant.ApplicantId} => {updateAccountResult.Result}");

                if (!updateAccountResult.Result)
                {
                    _app.StatusId = (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicationStatus.DisbursementError;
                }

                /*********************
                 * Make inquiry call on each joint or guarantor applicant to determine if that joint or guarantor should be added to
                 * account party relationship, and if that joint needs a credit card.
                 */
                foreach (var jointGuarantorApplicant in jointGuarantorApplicants)
                {
                    string errorMessage = string.Empty;

                    // These are the partyIds that are related to jointGuarantorApplicant
                    IList <RelationshipInfo> relationshipInfos = null;

                    var inquiryResult = _ccm.MakeInquiry(_restStrategy, jointGuarantorApplicant.PersonNumber, out errorMessage, out relationshipInfos);
                    result.AppendResult(inquiryResult);
                    tr.Log($"Inquiry result for ApplicantId {jointGuarantorApplicant.ApplicantId} => {inquiryResult.Result}");
                    tr.Log($"Inquiry errorMessage = {errorMessage}");
                    tr.Log($"Inquiry relationshipInfos.Count = {relationshipInfos?.Count}");

                    if (errorMessage.Equals("Relationship not found", StringComparison.InvariantCulture))
                    {
                        /*********************
                         * Applicant was not found in CCM, so call AddAccountPartyRelationship on this joint or guarantor applicant.
                         * Add joint or guarantor to the credit card account if there is NOT an accountNumber in the relationshipInfos of Inquiry response
                         * that equals Application > Credit Card Number.
                         */
                        tr.Log($"Creating an Account Party Relationship for ApplicantId {jointGuarantorApplicant.ApplicantId} in CCM");

                        var addAccountPartyRelationshipResult = _ccm.AddAccountPartyRelationship(_soapStrategy, jointGuarantorApplicant);
                        result.AppendResult(addAccountPartyRelationshipResult);
                        tr.Log($"AddAccountPartyRelationship result for ApplicantId {jointGuarantorApplicant.ApplicantId} => {addAccountPartyRelationshipResult.Result}");

                        /*********************
                         * Add Card for the non-organization joint applicant that was successfully added to the CCM account.
                         */
                        var isNonOrgJointApplicant =
                            !jointGuarantorApplicant.IsOrganization &&
                            jointGuarantorApplicant.ApplicantTypeId.GetValueOrDefault() == (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicantType.Joint;

                        if (addAccountPartyRelationshipResult.Result && isNonOrgJointApplicant)
                        {
                            var jointApplicant = jointGuarantorApplicant;

                            tr.Log($"Adding a card for ApplicantId {jointApplicant.ApplicantId} in CCM");

                            var addCardResult = _ccm.AddCard(_soapStrategy, jointApplicant);
                            result.AppendResult(addCardResult);
                            tr.Log($"AddCard result for ApplicantId {jointApplicant.ApplicationId} => {addCardResult.Result}");
                        }
                        else
                        {
                            tr.Log($"No card will be created for ApplicantId {jointGuarantorApplicant.ApplicantId} since it was NOT sucessfully added to account party relationship or is a guarantor applicant");
                        }
                    }
                    else
                    {
                        /*
                         * Person/Organization already exists in CCM
                         */
                        tr.Log($"ApplicantId {jointGuarantorApplicant.ApplicantId} already exists in CCM");
                    }
                }

                /*********************
                 * Make inquiry call on each authorized user to determine if that authorized user needs a credit card.
                 */
                foreach (var authorizedUser in _app.AuthorizedUsers)
                {
                    string errorMessage = string.Empty;

                    // These are the partyIds that are related to authorizedUser
                    IList <RelationshipInfo> relationshipInfos = null;

                    var inquiryResult = _ccm.MakeInquiry(_restStrategy, authorizedUser.PersonNumber, out errorMessage, out relationshipInfos);
                    result.AppendResult(inquiryResult);
                    tr.Log($"Inquiry result for AuthorizedUserId {authorizedUser.AuthorizedUserId} => {inquiryResult.Result}");
                    tr.Log($"Inquiry errorMessage = {errorMessage}");
                    tr.Log($"Inquiry relationshipInfos.Count = {relationshipInfos?.Count}");

                    if (errorMessage.Equals("Relationship not found", StringComparison.InvariantCulture))
                    {
                        /*********************
                         * Add authorized user to the credit card account if there is NOT an accountNumber in the relationshipInfos of Inquiry response
                         * that equals Application > Credit Card Number.
                         */
                        tr.Log($"Adding a card for AuthorizedUserId {authorizedUser.AuthorizedUserId} in CCM");

                        var addCardResult = _ccm.AddCard(_soapStrategy, authorizedUser);
                        result.AppendResult(addCardResult);
                        tr.Log($"AddCard result for AuthorizedUserId = {authorizedUser.AuthorizedUserId} => {addCardResult.Result}");
                    }
                    else
                    {
                        /*
                         * Authorized user already exists in CCM
                         */
                        tr.Log($"AuthorizedUserId {authorizedUser.AuthorizedUserId} already exists in CCM");
                    }
                }
            }

            return(result);
        }
Example #13
0
        /// <summary>
        /// Process for disbursing an application that is not an Add-On.
        /// </summary>
        /// <param name="primaryJointGuarantorApplicants"></param>
        /// <returns></returns>
        public BaseResult DisburseNonAddOn(IEnumerable <Applicant> primaryJointGuarantorApplicants)
        {
            var result = new BaseResult();

            using (var tr = new Tracer("LMS.Connector.CCM.CCMOrigination.DisburseNonAddOn"))
            {
                // Primary, joint, or guarantor applicants
                if (primaryJointGuarantorApplicants?.Any() == true)
                {
                    tr.Log($"Number of primary, joint, or guarantor applicants in ApplicationId {_app.ApplicationId} => {primaryJointGuarantorApplicants.Count()}");

                    foreach (var primaryJointGuarantorApplicant in primaryJointGuarantorApplicants)
                    {
                        /*********************
                         * Call AddPerson/AddOrganization on this person or organization, respectively.
                         */
                        tr.Log($"Adding ApplicantId {primaryJointGuarantorApplicant.ApplicantId} as a person or organization in CCM");
                        tr.Log($"ApplicantId {primaryJointGuarantorApplicant.ApplicantId} is ApplicantTypeId {primaryJointGuarantorApplicant.ApplicantTypeId}");

                        if (!primaryJointGuarantorApplicant.IsOrganization)
                        {
                            // Add the person applicant to CCM
                            var addPersonResult = _ccm.AddPerson(_soapStrategy, primaryJointGuarantorApplicant);
                            result.AppendResult(addPersonResult);
                            tr.Log($"AddPerson result for ApplicantId {primaryJointGuarantorApplicant.ApplicantId} => {addPersonResult.Result}");

                            if (addPersonResult.Result)
                            {
                                // Add this applicant to list of applicants that will need a card created
                                _applicantsAddedToCCM.Add(primaryJointGuarantorApplicant);
                            }
                        }
                        else
                        {
                            // Guarantors cannot be organizations
                            if (primaryJointGuarantorApplicant.ApplicantTypeId != (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicantType.Guarantor)
                            {
                                var primaryJointApplicant = primaryJointGuarantorApplicant;

                                // Add the organization applicant to CCM
                                var addOrganizationResult = _ccm.AddOrganization(_soapStrategy, primaryJointApplicant);
                                result.AppendResult(addOrganizationResult);
                                tr.Log($"AddOrganization result for ApplicantId {primaryJointApplicant.ApplicantId} => {addOrganizationResult.Result}");
                            }
                        }

                        if (!result.Result)
                        {
                            // Return to calling service if failure to AddPerson/AddOrganization on primary applicant
                            if (primaryJointGuarantorApplicant.ApplicantTypeId.GetValueOrDefault() == (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicantType.Primary)
                            {
                                _app.StatusId = (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicationStatus.DisbursementError;

                                return(result);
                            }
                        }
                    }

                    tr.Log($"_applicantsAddedToCCM.Count = {_applicantsAddedToCCM.Count}");

                    if (_app.AuthorizedUsers?.Count > 0)
                    {
                        tr.Log($"Number of authorized users in ApplicationId {_app.ApplicationId} => {_app.AuthorizedUsers.Count}");

                        foreach (var authorizedUser in _app.AuthorizedUsers)
                        {
                            /*********************
                             * Call AddPerson on this authorized user.
                             */
                            tr.Log($"Adding AuthorizedUserId {authorizedUser.AuthorizedUserId} as a person in CCM");

                            // Add the authorized user to CCM
                            var addAuthorizedUserResult = _ccm.AddAuthorizedUser(_soapStrategy, authorizedUser);
                            result.AppendResult(addAuthorizedUserResult);
                            tr.Log($"AddAuthorizedUser result for AuthorizedUserId {authorizedUser.AuthorizedUserId} => {addAuthorizedUserResult.Result}");

                            if (addAuthorizedUserResult.Result)
                            {
                                // Add this authorized user to the list of authorized users who will need a card created
                                _authorizedUsersAddedToCCM.Add(authorizedUser);
                            }
                        }
                    }

                    tr.Log($"_authorizedUsersAddedToCCM.Count = {_authorizedUsersAddedToCCM.Count}");

                    /*********************
                     * Add Account to create a new credit card account from an application that has a primary applicant.
                     */
                    var primaryApplicant = primaryJointGuarantorApplicants.SingleOrDefault(
                        a => a.ApplicantTypeId.GetValueOrDefault() == (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicantType.Primary
                        );

                    if (primaryApplicant != null)
                    {
                        tr.Log($"Creating an account for ApplicantId {primaryApplicant.ApplicantId} in CCM");

                        var addAccountResult = _ccm.AddAccount(_soapStrategy, primaryApplicant);
                        result.AppendResult(addAccountResult);
                        tr.Log($"AddAccount result for ApplicantId {primaryApplicant.ApplicationId} = {addAccountResult.Result}");

                        if (!addAccountResult.Result)
                        {
                            // Return to calling service if failure to AddAccount
                            _app.StatusId = (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicationStatus.DisbursementError;

                            return(result);
                        }
                    }
                    else
                    {
                        /*
                         * No primary applicant in the application
                         */
                        tr.Log("No primary applicant in the application");

                        // Return to calling service if failure to AddAccount
                        _app.StatusId = (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicationStatus.DisbursementError;

                        return(result);
                    }

                    /*********************
                     * Add Account Party Relationship for all joint and guarantor applicants.
                     */
                    var jointGuarantorApplicants = _app.Applicants.Where(
                        a => a.ApplicantTypeId.GetValueOrDefault() == (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicantType.Joint ||
                        a.ApplicantTypeId.GetValueOrDefault() == (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicantType.Guarantor
                        );

                    if (jointGuarantorApplicants?.Any() == true)
                    {
                        foreach (var jointGuarantorApplicant in jointGuarantorApplicants)
                        {
                            tr.Log($"Creating an Account Party Relationship for ApplicantId {jointGuarantorApplicant.ApplicantId} in CCM");

                            // Add joint or guarantor to the account
                            var addAccountPartyRelationshipResult = _ccm.AddAccountPartyRelationship(_soapStrategy, jointGuarantorApplicant);
                            result.AppendResult(addAccountPartyRelationshipResult);
                            tr.Log($"AddAccountPartyRelationship result for ApplicantId {jointGuarantorApplicant.ApplicationId} => {addAccountPartyRelationshipResult.Result}");
                        }
                    }
                    else
                    {
                        /*
                         * No joint or gurantor applicants in application
                         */
                        tr.Log("There are no joint or gurantor applicants in the application");
                    }

                    /*********************
                     * Add Card for each non-organization primary or joint applicant that was successfully added to the credit card account (CCM account).
                     */
                    if (_applicantsAddedToCCM.Count > 0)
                    {
                        tr.Log($"applicantsAddedToCCM.Count = {_applicantsAddedToCCM.Count}");
                        var nonOrgPrimaryOrJointApplicants = _applicantsAddedToCCM.Where(
                            a => !a.IsOrganization &&
                            (
                                a.ApplicantTypeId.GetValueOrDefault() == (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicantType.Primary ||
                                a.ApplicantTypeId.GetValueOrDefault() == (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicantType.Joint
                            )
                            );

                        if (nonOrgPrimaryOrJointApplicants?.Any() == true)
                        {
                            foreach (var nonOrgPrimaryOrJointApplicant in nonOrgPrimaryOrJointApplicants)
                            {
                                /*********************
                                 * Add Card for the non-organization applicant.
                                 */
                                tr.Log($"Adding a card for ApplicantId {nonOrgPrimaryOrJointApplicant.ApplicantId} in CCM");

                                var addCardResult = _ccm.AddCard(_soapStrategy, nonOrgPrimaryOrJointApplicant);
                                result.AppendResult(addCardResult);
                                tr.Log($"AddCard result for ApplicantId {nonOrgPrimaryOrJointApplicant.ApplicationId} => {addCardResult.Result}");
                            }
                        }
                        else
                        {
                            tr.Log($"No cards will be created since there were no non-organization primary or joint applicants sucessfully added to CCM account");
                        }
                    }
                    else
                    {
                        tr.Log("No calls to AddCard for applicants since there were no applicants that were successfully added to CCM account");
                    }

                    /*********************
                     * Add Card for each authorized user that was successfully added to the credit card account (CCM account).
                     */
                    if (_authorizedUsersAddedToCCM.Count > 0)
                    {
                        tr.Log($"authorizedUsersAddedToCCM.Count = {_authorizedUsersAddedToCCM.Count}");

                        foreach (var authorizedUser in _authorizedUsersAddedToCCM)
                        {
                            /*********************
                             * Add Card for the authorized user.
                             */
                            tr.Log($"Adding a card for AuthorizedUserId {authorizedUser.AuthorizedUserId} in CCM");

                            var addCardResult = _ccm.AddCard(_soapStrategy, authorizedUser);
                            result.AppendResult(addCardResult);
                            tr.Log($"AddCard result for AuthorizedUserId {authorizedUser.AuthorizedUserId} => {addCardResult.Result}");
                        }
                    }
                    else
                    {
                        tr.Log("No calls to AddCard for authorized users since there were no authorized users that were successfully added to CCM account");
                    }
                }
                else
                {
                    /*
                     * No primary, joint, or guarantor applicants in the application
                     */
                    result.Result = false;
                    result.AddError("There are no primary, joint, or guarantor applicants in the application");
                    tr.Log("There are no primary, joint, or guarantor applicants in the application");
                }
            }

            return(result);
        }
Example #14
0
        /// <summary>
        /// Checks for required fields prior to sending the request to the CCM service.
        /// </summary>
        /// <returns></returns>
        public BaseResult DisbursementValidation()
        {
            var result = new BaseResult();

            using (var tr = new Tracer("LMS.Connector.CCM.Validation.CCMValidation.DisbursementValidation"))
            {
                tr.Log("Calling ValidateInquiry");
                var validateInquiryResult = _validationManager.ValidateInquiry();
                result.AppendResult(validateInquiryResult);
                tr.Log($"ValidateInquiry result: {result.Result}");

                tr.Log($"_app.IsAddon = {_app.IsAddon}");
                if (!_app.IsAddon)
                {
                    tr.Log("Calling ValidateAddPerson");
                    var validateAddPersonResult = _validationManager.ValidateAddPerson();
                    result.AppendResult(validateAddPersonResult);
                    tr.Log($"ValidateAddPerson result: {validateAddPersonResult.Result}");

                    tr.Log("Calling ValidateAddOrganization");
                    var validateAddOrganizationResult = _validationManager.ValidateAddOrganization();
                    result.AppendResult(validateAddOrganizationResult);
                    tr.Log($"ValidateAddOrganization result: {validateAddOrganizationResult.Result}");

                    tr.Log("Calling ValidateAddAccount");
                    var validateAddAccountResult = _validationManager.ValidateAddAccount();
                    result.AppendResult(validateAddAccountResult);
                    tr.Log($"ValidateAddAccount result: {validateAddAccountResult.Result}");

                    tr.Log("Calling ValidateAddAccountPartyRelationship");
                    var validateAddAccountPartyRelationship = _validationManager.ValidateAddAccountPartyRelationship();
                    result.AppendResult(validateAddAccountPartyRelationship);
                    tr.Log($"ValidateAddAccountPartyRelationship result: {validateAddAccountPartyRelationship.Result}");

                    tr.Log("Calling ValidateAddCard");
                    var validateAddCardResult = _validationManager.ValidateAddCard();
                    result.AppendResult(validateAddCardResult);
                    tr.Log($"ValidateAddCard result: {validateAddCardResult.Result}");
                }
                else
                {
                    tr.Log("Calling ValidateAddPerson");
                    var validateAddPersonResult = _validationManager.ValidateAddPerson();
                    result.AppendResult(validateAddPersonResult);
                    tr.Log($"ValidateAddPerson result: {validateAddPersonResult.Result}");

                    tr.Log("Calling ValidateAddOrganization");
                    var validateAddOrganizationResult = _validationManager.ValidateAddOrganization();
                    result.AppendResult(validateAddOrganizationResult);
                    tr.Log($"ValidateAddOrganization result: {validateAddOrganizationResult.Result}");

                    tr.Log("Calling ValidateUpdateAccount");
                    var validateUpdateAccountResult = _validationManager.ValidateUpdateAccount();
                    result.AppendResult(validateUpdateAccountResult);
                    tr.Log($"ValidateUpdateAccount result: {validateUpdateAccountResult.Result}");

                    tr.Log("Calling ValidateAddAccountPartyRelationship");
                    var validateAddAccountPartyRelationshipResult = _validationManager.ValidateAddAccountPartyRelationship();
                    result.AppendResult(validateAddAccountPartyRelationshipResult);
                    tr.Log($"ValidateAddAccountPartyRelationship result: {validateAddAccountPartyRelationshipResult.Result}");

                    tr.Log("Calling ValidateAddCard");
                    var validateAddCardResult = _validationManager.ValidateAddCard();
                    result.AppendResult(validateAddCardResult);
                    tr.Log($"ValidateAddCard result: {validateAddCardResult.Result}");
                }
            }

            return(result);
        }
Example #15
0
        public BaseResult ValidateAddPerson()
        {
            var result = new BaseResult();

            try
            {
                if (_app.ApplicationId > 0)
                {
                    if (string.IsNullOrWhiteSpace(_app.ApplicationId.ToString()))
                        result.AddError("The Application > Application Id is required");

                    var persons = _app.Applicants.Where(a => !a.IsOrganization);

                    if (persons?.Any() == true)
                    {
                        foreach (var applicant in persons)
                        {
                            // Applicant
                            if (string.IsNullOrWhiteSpace(applicant.PersonNumber))
                                result.AddError("The Application > Applicants > Person Number is required");

                            if (string.IsNullOrWhiteSpace(applicant.LastName))
                                result.AddError("The Application > Applicants > Last Name is required");

                            if (string.IsNullOrWhiteSpace(applicant.FirstName))
                                result.AddError("The Application > Applicants > First Name is required");

                            var currentAddress = applicant.Addresses.FirstOrDefault(
                                a => a.AddressTypeId == _lmsRepository.GetLookupIdByTypeAndCode(LookupTypes.AddressType, LookupCodes.AddressType.Current)
                            );

                            if (currentAddress != null)
                            {
                                if (string.IsNullOrWhiteSpace(currentAddress.Address1))
                                    result.AddError("The Application > Applicants > Addresses > Address 1 is required");

                                if (string.IsNullOrWhiteSpace(currentAddress.City))
                                    result.AddError("The Application > Applicants > Addresses > City is required");

                                if (!currentAddress.StateId.HasValue)
                                    result.AddError("The Application > Applicants > Addresses > State is required");

                                if (string.IsNullOrWhiteSpace(currentAddress.PostalCode))
                                    result.AddError("The Application > Applicants > Addresses > Postal Code is required");
                            }

                            var phoneMobile = applicant.Phones.FirstOrDefault(
                                p => p.PhoneTypeId == _lmsRepository.GetLookupIdByTypeAndCode(LookupTypes.PhoneType, LookupCodes.PhoneType.Mobile)
                            );
                            var phoneHome = applicant.Phones.FirstOrDefault(
                                p => p.PhoneTypeId == _lmsRepository.GetLookupIdByTypeAndCode(LookupTypes.PhoneType, LookupCodes.PhoneType.Home)
                            );
                            if (phoneMobile != null)
                            {
                                var cityAreaCodeHV = phoneMobile.HostValues.Where(
                                    hv => hv.Field1.Equals("AddPerson.Message.DataUpdate.Person.PrimaryPhone.CityAreaCode", StringComparison.InvariantCulture)
                                );
                                var localPhoneNumberHV = phoneMobile.HostValues.Where(
                                    hv => hv.Field1.Equals("AddPerson.Message.DataUpdate.Person.PrimaryPhone.LocalPhoneNumber", StringComparison.InvariantCulture)
                                );

                                if (cityAreaCodeHV?.Any() == true)
                                {
                                    if (!string.IsNullOrWhiteSpace(cityAreaCodeHV?.SingleOrDefault().Value) && string.IsNullOrWhiteSpace(phoneMobile.PhoneNumber))
                                    {
                                        result.AddError("The Application > Applicants > Phones > Phone Number is required");
                                    }
                                }
                                else if (localPhoneNumberHV?.Any() == true)
                                {
                                    if (!string.IsNullOrWhiteSpace(localPhoneNumberHV?.SingleOrDefault().Value) && string.IsNullOrWhiteSpace(phoneMobile.PhoneNumber))
                                    {
                                        result.AddError("The Application > Applicants > Phones > Phone Number is required");
                                    }
                                }
                            }
                            else if (phoneHome != null && phoneMobile == null)
                            {
                                var cityAreaCodeHV = phoneHome.HostValues.Where(
                                    hv => hv.Field1.Equals("AddPerson.Message.DataUpdate.Person.PrimaryPhone.CityAreaCode", StringComparison.InvariantCulture)
                                );
                                var localPhoneNumberHV = phoneHome.HostValues.Where(
                                    hv => hv.Field1.Equals("AddPerson.Message.DataUpdate.Person.PrimaryPhone.LocalPhoneNumber", StringComparison.InvariantCulture)
                                );

                                if (cityAreaCodeHV?.Any() == true)
                                {
                                    if (!string.IsNullOrWhiteSpace(cityAreaCodeHV?.SingleOrDefault().Value) && string.IsNullOrWhiteSpace(phoneHome.PhoneNumber))
                                    {
                                        result.AddError("The Application > Applicants > Phones > Phone Number is required");
                                    }
                                }
                                else if (localPhoneNumberHV?.Any() == true)
                                {
                                    if (!string.IsNullOrWhiteSpace(localPhoneNumberHV?.SingleOrDefault().Value) && string.IsNullOrWhiteSpace(phoneHome.PhoneNumber))
                                    {
                                        result.AddError("The Application > Applicants > Phones > Phone Number is required");
                                    }
                                }
                            }

                            if (!result.Result)
                            {
                                _baseResult.AppendResult(result);

                                return result;
                            }
                        }
                    }

                    foreach (var authUser in _app.AuthorizedUsers)
                    {
                        // Authorized User
                        if (string.IsNullOrWhiteSpace(authUser.PersonNumber))
                            result.AddError("The Application > Authorized User > Person Number is required");

                        if (string.IsNullOrWhiteSpace(authUser.LastName))
                            result.AddError("The Application > Authorized User > Last Name is required");

                        if (string.IsNullOrWhiteSpace(authUser.FirstName))
                            result.AddError("The Application > Authorized User > First Name is required");

                        var currentAddress = authUser.Addresses.FirstOrDefault(
                            a => a.AddressTypeId == _lmsRepository.GetLookupIdByTypeAndCode(LookupTypes.AddressType, LookupCodes.AddressType.Current)
                        );

                        if (currentAddress != null)
                        {
                            if (string.IsNullOrWhiteSpace(currentAddress.Address1))
                                result.AddError("The Application > Authorized Users > Addresses > Address 1 is required");

                            if (string.IsNullOrWhiteSpace(currentAddress.City))
                                result.AddError("The Application > Authorized Users > Addresses > City is required");

                            if (!currentAddress.StateId.HasValue)
                                result.AddError("The Application > Authorized Users > Addresses > State is required");

                            if (string.IsNullOrWhiteSpace(currentAddress.PostalCode))
                                result.AddError("The Application > Authorized Users > Addresses > Postal Code is required");
                        }

                        var phoneMobile = authUser.Phones.FirstOrDefault(
                            p => p.PhoneTypeId == _lmsRepository.GetLookupIdByTypeAndCode(LookupTypes.PhoneType, LookupCodes.PhoneType.Mobile)
                        );
                        var phoneHome = authUser.Phones.FirstOrDefault(
                            p => p.PhoneTypeId == _lmsRepository.GetLookupIdByTypeAndCode(LookupTypes.PhoneType, LookupCodes.PhoneType.Home)
                        );
                        if (phoneMobile != null)
                        {
                            var cityAreaCodeHV = phoneMobile.HostValues.Where(
                                hv => hv.Field1.Equals("AddPerson.Message.DataUpdate.Person.PrimaryPhone.CityAreaCode", StringComparison.InvariantCulture)
                            );
                            var localPhoneNumberHV = phoneMobile.HostValues.Where(
                                hv => hv.Field1.Equals("AddPerson.Message.DataUpdate.Person.PrimaryPhone.LocalPhoneNumber", StringComparison.InvariantCulture)
                            );

                            if (cityAreaCodeHV?.Any() == true)
                            {
                                if (!string.IsNullOrWhiteSpace(cityAreaCodeHV?.SingleOrDefault().Value) && string.IsNullOrWhiteSpace(phoneMobile.PhoneNumber))
                                {
                                    result.AddError("The Application > Applicants > Phones > Phone Number is required");
                                }
                            }
                            else if (localPhoneNumberHV?.Any() == true)
                            {
                                if (!string.IsNullOrWhiteSpace(localPhoneNumberHV?.SingleOrDefault().Value) && string.IsNullOrWhiteSpace(phoneMobile.PhoneNumber))
                                {
                                    result.AddError("The Application > Applicants > Phones > Phone Number is required");
                                }
                            }
                        }
                        else if (phoneHome != null && phoneMobile == null)
                        {
                            var cityAreaCodeHV = phoneHome.HostValues.Where(
                                hv => hv.Field1.Equals("AddPerson.Message.DataUpdate.Person.PrimaryPhone.CityAreaCode", StringComparison.InvariantCulture)
                            );
                            var localPhoneNumberHV = phoneHome.HostValues.Where(
                                hv => hv.Field1.Equals("AddPerson.Message.DataUpdate.Person.PrimaryPhone.LocalPhoneNumber", StringComparison.InvariantCulture)
                            );

                            if (cityAreaCodeHV?.Any() == true)
                            {
                                if (!string.IsNullOrWhiteSpace(cityAreaCodeHV?.SingleOrDefault().Value) && string.IsNullOrWhiteSpace(phoneHome.PhoneNumber))
                                {
                                    result.AddError("The Application > Applicants > Phones > Phone Number is required");
                                }
                            }
                            else if (localPhoneNumberHV?.Any() == true)
                            {
                                if (!string.IsNullOrWhiteSpace(localPhoneNumberHV?.SingleOrDefault().Value) && string.IsNullOrWhiteSpace(phoneHome.PhoneNumber))
                                {
                                    result.AddError("The Application > Applicants > Phones > Phone Number is required");
                                }
                            }
                        }

                        if (!result.Result)
                        {
                            _baseResult.AppendResult(result);

                            return result;
                        }
                    }
                }
                else
                {
                    result.AddError("The Application > Application Id is required");
                }
            }
            catch (ArgumentNullException ane)
            {
                result.AddError($"Source or predicate is null: {ane.ParamName}");
                Utility.LogError(ane, "LMS.Connector.CCM.Validation.ValidationManager.ValidateAddPerson");
            }
            catch (InvalidOperationException ioe)
            {
                result.AddError($"The source sequence is empty or more than one element satisfies the condition in predicate: {ioe.Source}");
                Utility.LogError(ioe, "LMS.Connector.CCM.Validation.ValidationManager.ValidateAddPerson");
            }
            catch (Exception ex)
            {
                result.AddError("Exception caught in LMS.Connector.CCM.Validation.ValidationManager.ValidateAddPerson. See error log for more details.");
                Utility.LogError(ex, "LMS.Connector.CCM.Validation.ValidationManager.ValidateAddPerson");
            }

            _baseResult.AppendResult(result);

            return result;
        }