예제 #1
0
        public BaseResult ValidateInquiry()
        {
            var result = new BaseResult();

            try
            {
                foreach (var applicant in _app.Applicants)
                {
                    if (string.IsNullOrWhiteSpace(applicant.PersonNumber))
                    {
                        result.AddError("The Application > Applicants > Person Number is required");
                        return result;
                    }
                }

                foreach (var authorizedUser in _app.AuthorizedUsers)
                {
                    if (string.IsNullOrWhiteSpace(authorizedUser.PersonNumber))
                    {
                        result.AddError("The Application > Authorized User > Person Number is required");
                        return result;
                    }
                }
            }
            catch (Exception ex)
            {
                result.AddError("Exception caught in LMS.Connector.CCM.Validation.ValidationManager.ValidateInquiry. See error log for more details.");
                Utility.LogError(ex, "LMS.Connector.CCM.Validation.ValidationManager.ValidateInquiry");
            }

            return result;
        }
예제 #2
0
        public BaseResult ValidateUpdateAccount()
        {
            var result = new BaseResult();

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

                    if (string.IsNullOrWhiteSpace(_app.CreditCardNumber))
                        result.AddError("The Application > Credit Card Number is required");

                    if (!_app.FinalLoanAmount.HasValue)
                        result.AddError("The Application > Final Loan Amount is required");
                }
                else
                {
                    result.AddError("The Application > Application Id is required");
                }
            }
            catch (Exception ex)
            {
                result.AddError("Exception caught in LMS.Connector.CCM.Validation.ValidationManager.ValidateUpdateAccount. See error log for more details.");
                Utility.LogError(ex, "LMS.Connector.CCM.Validation.ValidationManager.ValidateUpdateAccount");
            }

            _baseResult.AppendResult(result);

            return result;
        }
        public async Task <BaseResult <DisplayPlatformTicketModel> > BookPlatformTicket(string userId, PlatformTicketModel model)
        {
            BaseResult <DisplayPlatformTicketModel> result = new BaseResult <DisplayPlatformTicketModel>();

            if (model != null && !String.IsNullOrWhiteSpace(userId))
            {
                try
                {
                    //Get user
                    var user = await _userRepository.GetUser(userId);

                    if (user != null)
                    {
                        PlatformTicketDataModel dataModel = new PlatformTicketDataModel();
                        dataModel.InjectFrom(model);
                        dataModel.TicketStatus = TicketStatus.Booked;
                        dataModel.Id           = Guid.NewGuid().ToString();
                        dataModel.UserId       = user.Id;
                        //Insert data to mongo

                        var platformTicketCollection = _database.GetCollection <PlatformTicketDataModel>("cPTickets");
                        await platformTicketCollection.InsertOneAsync(dataModel);

                        var filter = Builders <PlatformTicketDataModel> .Filter.Eq("Id", dataModel.Id);

                        var bookedTicket = await platformTicketCollection.Find(filter).ToListAsync();

                        DisplayPlatformTicketModel displaymodel = null;

                        if (bookedTicket != null && bookedTicket.Count == 1)
                        {
                            displaymodel = Convert(bookedTicket.FirstOrDefault());
                        }
                        result.Suceeded = true;
                        result.Value    = displaymodel;
                    }
                    else
                    {
                        result.Suceeded = false;
                        result.AddError("User is unauthenticated.");
                    }
                }
                catch (Exception)
                {
                    result.Suceeded = false;
                    result.AddError("Error while booking platformticket, please try after some time.");
                }
            }
            else
            {
                result.Suceeded = false;
                result.SetRequiredFieldsMissing("Fields missing");
            }

            return(result);
        }
        public async Task <BaseResult <StringIdResult> > CreateUser(RegisterModel model)
        {
            var result = new BaseResult <StringIdResult>();

            if (model != null)
            {
                var valResult = _registerUserValidator.Validate(model);

                if (valResult.IsValid)
                {
                    try
                    {
                        var userCollection = _database.GetCollection <RegisterModel>("cUsers");

                        //find user by phone number if not exist then only register
                        var filter = Builders <RegisterModel> .Filter.Eq("PhoneNumber", model.PhoneNumber);

                        var user = await userCollection.Find(filter).ToListAsync();

                        if (user.Count == 0)
                        {
                            model.Id = Guid.NewGuid().ToString();

                            await userCollection.InsertOneAsync(model);                    result.Suceeded = true;

                            StringIdResult idResult = new StringIdResult();
                            idResult.Id  = model.Id;
                            result.Value = idResult;
                        }
                        else
                        {
                            result.Suceeded = false;
                            result.AddError("Already registered phone number");
                        }
                    }
                    catch (Exception)
                    {
                        result.Suceeded = false;
                        result.AddError("An error occured while registering user");
                    }
                }
                else
                {
                    result.Suceeded = false;
                    result.Errors.AddRange(valResult.Errors.ToErrorStringList());
                }
            }
            else
            {
                result.Suceeded = false;
                result.AddError("User can't be null");
            }

            return(result);
        }
        public async Task <BaseResult <StringIdResult> > GetUser(LoginModel model)
        {
            var result = new BaseResult <StringIdResult>();

            if (model != null)
            {
                var valResult = _userLoginValidator.Validate(model);

                if (valResult.IsValid)
                {
                    try
                    {
                        var userCollection = _database.GetCollection <RegisterModel>("cUsers");

                        var builder = Builders <RegisterModel> .Filter;

                        var filter = builder.Eq("PhoneNumber", model.PhoneNumber) & builder.Eq("Password", model.Password);

                        var users = await userCollection.Find(filter).ToListAsync();

                        if (users.Count > 0)
                        {
                            StringIdResult r = new StringIdResult();
                            r.Id = users[0].Id;

                            result.Value    = r;
                            result.Suceeded = true;
                        }
                        else
                        {
                            result.Suceeded = false;
                            result.AddError("Wrong phoneNumber or password.");
                        }
                    }
                    catch (Exception)
                    {
                        result.Suceeded = false;
                        result.AddError("An error occured while registering user.");
                    }
                }
                else
                {
                    result.Suceeded = false;
                    result.Errors.AddRange(valResult.Errors.ToErrorStringList());
                }
            }
            else
            {
                result.SetRequiredFieldsMissing("PhoneNumber", "Password");
                result.Suceeded = false;
            }

            return(result);
        }
예제 #6
0
        public async Task <BaseResult <StringIdResult> > CancelTicket(string userId, string ticketId)
        {
            BaseResult <StringIdResult> result = new BaseResult <StringIdResult>();

            try
            {
                if (!String.IsNullOrWhiteSpace(userId) && !String.IsNullOrWhiteSpace(userId))
                {
                    //Get User
                    var user = await _userRepository.GetUser(userId);

                    if (user != null)
                    {
                        //Get Ticket by Id
                        var ticketCollection = _database.GetCollection <TicketDataModel>("cTickets");
                        var filter           = Builders <TicketDataModel> .Filter.Eq("Id", ticketId);

                        var update = Builders <TicketDataModel> .Update.Set("TicketStatus", TicketStatus.Canceled);

                        var ticket = await ticketCollection.UpdateOneAsync(filter, update);

                        if (ticket.ModifiedCount == 1)
                        {
                            StringIdResult idResult = new StringIdResult();
                            idResult.Id = ticketId;

                            result.Suceeded = true;
                            result.Value    = idResult;
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        result.Suceeded = false;
                        result.AddError("user is unauthenticated");
                    }
                }
                else
                {
                    result.Suceeded = false;
                    result.SetRequiredFieldsMissing("Fields missing");
                }
            }
            catch (Exception)
            {
                result.Suceeded = false;
                result.AddError("Error while cancelling ticket, please try after some time.");
            }

            return(result);
        }
예제 #7
0
        public override void OnActionExecuting(ActionExecutingContext actionContext)
        {
            if (actionContext.ModelState.IsValid)
            {
                return;
            }
            var result = new BaseResult();

            foreach (var key in actionContext.ModelState.Keys)
            {
                var modelState = actionContext.ModelState[key];
                foreach (var error in modelState.Errors)
                {
                    var errorDetail = error.ErrorMessage;
                    if (string.IsNullOrEmpty(errorDetail))
                    {
                        var splittedPrpName = key.Split('.');
                        var prpName         = splittedPrpName.Length > 1 ? splittedPrpName[1] : key;
                        errorDetail = prpName + " is not valid!";
                    }
                    result.AddError(errorDetail);
                }
            }

            actionContext.Result = new BadRequestObjectResult(result);
        }
예제 #8
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);
        }
예제 #9
0
        public async Task <BaseResult <List <DisplayTicketModel> > > GetTicketsByUserId(string userId)
        {
            BaseResult <List <DisplayTicketModel> > result = new BaseResult <List <DisplayTicketModel> >();

            if (!String.IsNullOrWhiteSpace(userId))
            {
                //Get Tickets by userId

                var ticketCollection = _database.GetCollection <TicketDataModel>("cTickets");
                var filter           = Builders <TicketDataModel> .Filter.Eq("UserId", userId);

                var tickets = await ticketCollection.Find(filter).ToListAsync();

                if (tickets != null && tickets.Count > 0)
                {
                    List <DisplayTicketModel> model = Convert(tickets);
                    result.Suceeded = true;
                    result.Value    = model;
                }
                else
                {
                    result.Suceeded = true;
                    result.AddError("User don't have any tickets");
                }
            }
            else
            {
                result.Suceeded = false;
                result.SetRequiredFieldsMissing("userId");
            }

            return(result);
        }
예제 #10
0
        public BaseResult TestConnections(IList <HostParameter> connectorParams)
        {
            var result = new BaseResult();

            using (var tr = new Tracer("LMS.Connector.CCM.Service.Api.TestConnections"))
            {
                try
                {
                    var userName       = connectorParams.SingleOrDefault(p => p.Name == "CCM_USERNAME")?.Value;
                    var password       = connectorParams.SingleOrDefault(p => p.Name == "CCM_PASSWORD")?.Value;
                    var facility       = connectorParams.SingleOrDefault(p => p.Name == "CCM_FACILITY")?.Value;
                    var soapServiceUrl = connectorParams.SingleOrDefault(p => p.Name == "CCM_SOAP_SERVICE_URL")?.Value;
                    var restServiceUrl = connectorParams.SingleOrDefault(p => p.Name == "CCM_REST_SERVICE_URL")?.Value;
                    _userToken = connectorParams.SingleOrDefault(p => p.Name == "USERTOKEN")?.Value;

                    // Set up fake primary applicant for testing connection
                    var app = GetTestApplication();

                    var soapCredentials = new Credentials()
                    {
                        BaseUrl  = soapServiceUrl,
                        Username = userName,
                        Password = password,
                        Facility = facility
                    };
                    tr.LogObject(soapCredentials);

                    var restCredentials = new Credentials()
                    {
                        BaseUrl  = restServiceUrl,
                        Username = userName,
                        Password = password,
                        Facility = facility
                    };
                    tr.LogObject(restCredentials);

                    var soapStrategy = new SoapStrategy(app, _userToken, soapCredentials);

                    var restStrategy = new RestStrategy(app, _userToken, restCredentials);

                    var ccm = new CCMOrigination(app, _userToken, restStrategy, soapStrategy);

                    result = ccm.TestConnections(userName, password, facility, soapServiceUrl, restServiceUrl);
                }
                catch (Exception ex)
                {
                    tr.LogException(ex);
                    result.ExceptionId = Utility.LogError(ex, "LMS.Connector.CCM.Service.Api.TestConnections");
                    result.AddError(ex.Message);
                    throw;
                }

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

            return(result);
        }
예제 #11
0
        public BaseResult ValidateAddAccount()
        {
            var result = new BaseResult();

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

                    if (!_app.FinalLoanAmount.HasValue)
                        result.AddError("The Application > Final Loan Amount is required");

                    var primaryApplicant = _app.Applicants.SingleOrDefault(
                        a => a.ApplicantTypeId.GetValueOrDefault() == (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicantType.Primary
                    );

                    if (string.IsNullOrWhiteSpace(primaryApplicant?.PersonNumber))
                        result.AddError("The Application > Applicants > Person Number is required");

                    var productNameHV = _app.HostValues.Where(hv => hv.Field1.Equals("AddAccount.Message.DataUpdate.Account.ProductName", StringComparison.InvariantCulture));

                    if (productNameHV?.Any() == false || string.IsNullOrWhiteSpace(productNameHV?.SingleOrDefault().Value))
                    {
                        result.AddError(GetRulesOnlyErrorMessage("AddAccount.Message.DataUpdate.Account.ProductName"));
                    }
                }
                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.ValidateAddAccount");
            }
            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.ValidateAddAccount");
            }
            catch (Exception ex)
            {
                result.AddError("Exception caught in LMS.Connector.CCM.Validation.ValidationManager.ValidateAddAccount. See error log for more details.");
                Utility.LogError(ex, "LMS.Connector.CCM.Validation.ValidationManager.ValidateAddAccount");
            }

            _baseResult.AppendResult(result);

            return result;
        }
예제 #12
0
        public BaseResult DeleteTask(Guid userId, Guid projectId, Guid taskId)
        {
            var toReturn = new BaseResult();
            var user     = Get(userId);
            var project  = user.Projects.FirstOrDefault(x => x.Id.Equals(projectId));

            if (project == null)
            {
                return(toReturn.AddError("Project Not Found!"));
            }

            var index = project.Tasks.FindIndex(x => x.Id.Equals(taskId));

            if (index == -1)
            {
                return(toReturn.AddError("Task Not Found!"));
            }

            project.Tasks.RemoveAt(index);
            Update(user);
            return(toReturn.AddSuccess());
        }
예제 #13
0
        public BaseResult DeleteProject(Guid userId, Guid projectId)
        {
            var toReturn = new BaseResult();
            var user     = Get(userId);
            var index    = user.Projects.FindIndex(x => x.Id.Equals(projectId));

            if (index == -1)
            {
                return(toReturn.AddError("Project Not Found!"));
            }

            user.Projects.RemoveAt(index);
            Update(user);
            return(toReturn.AddSuccess());
        }
예제 #14
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);
        }
예제 #15
0
        public BaseResult UpdateProject(Guid userId, Project project)
        {
            var toReturn = new BaseResult();
            var user     = Get(userId);
            var index    = user.Projects.FindIndex(x => x.Id.Equals(project.Id));

            if (index == -1)
            {
                return(toReturn.AddError("Project Not Found!"));
            }

            user.Projects[index] = project;
            Update(user);
            return(toReturn.AddSuccess());
        }
예제 #16
0
        /// <summary>
        /// Disburses the Application to CCM.
        /// </summary>
        /// <param name="userToken"></param>
        /// <param name="app"></param>
        /// <returns></returns>
        public BaseResult DisburseApplication(string userToken, ref Application app)
        {
            var result = new BaseResult();

            _app       = app;
            _userToken = userToken;

            using (var tr = new Tracer("LMS.Connector.CCM.Service.Api.DisburseApplication"))
            {
                var restStrategy = new RestStrategy(app, userToken);

                var soapRepository = new SoapRepository(userToken);
                var soapStrategy   = new SoapStrategy(app, userToken, soapRepository);
                soapStrategy.Repository = soapRepository;

                var ccm = new CCMOrigination(app, userToken, restStrategy, soapStrategy);

                try
                {
                    result = ccm.DisburseApplication();
                }
                catch (Exception ex)
                {
                    tr.LogException(ex);
                    result.ExceptionId = Utility.LogError(ex, "LMS.Connector.CCM.Service.Api.DisburseApplication");
                    result.AddError(ex.Message);
                }

                if (result.Result)
                {
                    result.AddMessage(MessageType.Success, "Loan product disbursed successfully.");
                    result.AddMessage(MessageType.Success, "Application has been disbursed.");

                    app.IsLoanDisbursed    = true;
                    app.StatusId           = (int)Akcelerant.Lending.Lookups.Constants.Values.ApplicationStatus.Disbursed;
                    app.DisbursementUserId = app.LoggedInUser.UserId;

                    tr.Log($"ApplicationId {app.ApplicationId} DisbursementUserId => {app.LoggedInUser.UserId}");
                }

                tr.Log($"ApplicationId {app.ApplicationId} IsLoanDisbursed => {app.IsLoanDisbursed}");
                tr.Log($"ApplicationId {app.ApplicationId} StatusId => {app.StatusId}");
                tr.Log($"LMS.Connector.CCM.Service.Api.DisburseApplication result => {result.Result}");
            }

            return(result);
        }
예제 #17
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);
        }
예제 #18
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;
        }
예제 #19
0
        public BaseResult ValidateAddCard()
        {
            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 person in persons)
                        {
                            // Applicant
                            if (string.IsNullOrWhiteSpace(person.PersonNumber))
                                result.AddError("The Application > Applicants > Person Number is required");

                            var embossingLine1HV = person.HostValues.Where(hv => hv.Field1.Equals("AddCard.Message.DataUpdate.Card.EmbossingLine1", StringComparison.InvariantCulture));

                            if (embossingLine1HV?.Any() == false || string.IsNullOrWhiteSpace(embossingLine1HV?.SingleOrDefault().Value))
                            {
                                result.AddError(GetRulesOnlyErrorMessage("AddCard.Message.DataUpdate.Card.EmbossingLine1"));
                            }

                            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");

                        var embossingLine1HV = authUser.HostValues.Where(hv => hv.Field1.Equals("AddCard.Message.DataUpdate.Card.EmbossingLine1", StringComparison.InvariantCulture));

                        if (embossingLine1HV?.Any() == false || string.IsNullOrWhiteSpace(embossingLine1HV.SingleOrDefault().Value))
                        {
                            result.AddError(GetRulesOnlyErrorMessage("AddCard.Message.DataUpdate.Card.EmbossingLine1"));
                        }

                        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.ValidateAddCard");
            }
            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.ValidateAddCard");
            }
            catch (Exception ex)
            {
                result.AddError("Exception caught in LMS.Connector.CCM.Validation.ValidationManager.ValidateAddCard. See error log for more details.");
                Utility.LogError(ex, "LMS.Connector.CCM.Validation.ValidationManager.ValidateAddCard");
            }

            _baseResult.AppendResult(result);

            return result;
        }
예제 #20
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);
        }
예제 #21
0
        public JsonResult TestConnections(CCMAdminModel model)
        {
            var result = new BaseResult();

            using (var tr = new Tracer("LMS.Connector.CCM.Web.CCMAdminController.TestConnections(CCMAdminModel)"))
            {
                var validationResult = ValidateParameters(model);

                if (!string.IsNullOrWhiteSpace(validationResult))
                {
                    result.Result = false;
                    result.AddMessage(MessageType.Error, validationResult);

                    return(result.ToJsonResult());
                }

                var connectorParams = new List <HostParameter>()
                {
                    new HostParameter("CCM_USERNAME", model.UserName.Trim()),
                    new HostParameter("CCM_PASSWORD", model.Password.Trim()),
                    new HostParameter("CCM_FACILITY", model.Facility.Trim()),
                    new HostParameter("CCM_SOAP_SERVICE_URL", model.SoapServiceUrl.Trim()),
                    new HostParameter("CCM_REST_SERVICE_URL", model.RestServiceUrl.Trim()),
                    new HostParameter("USERTOKEN", WebUtil.UserToken)
                };

                tr.LogObject(connectorParams);

                try
                {
                    using (var svc = new Akcelerant.Lending.Client.Services.DisburseApplication())
                    {
                        svc.SetEndpointAddress(GetDisbursementProviderServiceLocation(DISBURSEMENT_PROVIDER_ID));

                        result = svc.TestConnection(connectorParams);

                        if (result.Result)
                        {
                            result.Messages.Add(new Akcelerant.Core.Data.DTO.Result.Message(MessageType.Success, "Connection to CCM was successful."));
                            tr.LogObject(result);
                        }
                        else
                        {
                            result.Result = false;
                            result.Messages.Clear();
                            result.AddError("Connection to the Credit Card Management - Loan Origination service failed. Please validate your credentials and try again.");
                        }
                    }
                }
                catch (FaultException <ExceptionDetail> ex)
                {
                    tr.LogException(ex);
                    result.Result      = false;
                    result.ExceptionId = Utility.LogError(ex, "LMS.Connector.CCM.Web.Controllers.CCMAdminController.TestConnection");
                    result.AddError("Connection to the Credit Card Management - Loan Origination service failed. Please validate your credentials and try again.");
                }
                catch (Exception ex)
                {
                    tr.LogException(ex);
                    result.Result      = false;
                    result.ExceptionId = Utility.LogError(ex, "LMS.Connector.CCM.Web.Controllers.CCMAdminController.TestConnection");
                    result.AddError("Connection to the Credit Card Management - Loan Origination service failed. Please validate your credentials and try again.");
                }
            }

            return(result.ToJsonResult());
        }