Beispiel #1
0
        /// <summary>
        /// Upserts the customer requested loan.
        /// </summary>
        /// <param name="requestedLoan">The requested loan.</param>
        public Optional <int> UpsertCustomerRequestedLoan(CustomerRequestedLoan requestedLoan)
        {
            using (var connection = GetOpenedSqlConnection2()) {
                var cmd = GetUpsertGenerator(requestedLoan)
                          .WithConnection(connection.SqlConnection())
                          .WithSkipColumns(o => o.Id)
                          .WithMatchColumns(o => o.CustomerId)
                          .WithOutputColumns(o => o.Id)
                          .WithTableName(Tables.CustomerRequestedLoan)
                          .Verify()
                          .GenerateCommand();

                using (var sqlCommand = cmd) {
                    return(ExecuteScalarAndLog <int>(sqlCommand));
                }
            }
        }
        public JsonResult RequestedLoan(FrontRequestedLoanModel requested)
        {
            var customer = this.context.Customer;

            Log.Info("Save requested loan for customer " + customer.Id);
            var requestedLoan = new CustomerRequestedLoan {
                Created    = DateTime.UtcNow,
                Amount     = requested.Amount,
                Term       = requested.Term,
                CustomerId = customer.Id
            };

            customer.CustomerRequestedLoan.Add(requestedLoan);
            this.customerRepository.Save(customer);

            var requestedLoanResult = new FrontRequestedLoanModel {
                Created    = DateTime.UtcNow,
                Amount     = requested.Amount,
                Term       = requested.Term,
                CustomerId = customer.Id
            };

            return(Json(requestedLoanResult, JsonRequestBehavior.AllowGet));
        }         // RequestedLoan Save
Beispiel #3
0
        /// <summary>
        /// Updates customer.
        /// </summary>
        /// <param name="customer">The customer.</param>
        /// <param name="requestedAmount">The requested amount.</param>
        /// <param name="sourceRefList">The source reference list.</param>
        /// <param name="visitTimeList">The visit time list.</param>
        /// <param name="campaignSrcRef">The campaign source reference.</param>
        /// <param name="addresses">The addresses.</param>
        /// <param name="phoneNumbers">The phone numbers.</param>
        /// <returns></returns>
        public InfoAccumulator UpdateCustomer(Customer customer, decimal requestedAmount, string sourceRefList, string visitTimeList,
                                              CampaignSourceRef campaignSrcRef, IEnumerable <CustomerAddress> addresses, IEnumerable <CustomerPhone> phoneNumbers)
        {
            InfoAccumulator info = new InfoAccumulator();

            using (var unitOfWork = new UnitOfWork()) {
                DateTime now = DateTime.UtcNow;

                int customerId = (int)CustomerQueries.UpsertCustomer(customer);
                if (customerId < 1)
                {
                    info.AddError("could not save customer");
                    return(info);
                }

                bool isSuccess = true;

                if (requestedAmount > 0)
                {
                    CustomerRequestedLoan requestedLoan = new CustomerRequestedLoan {
                        CustomerId = customerId,
                        Amount     = requestedAmount,
                        Created    = DateTime.UtcNow
                    };

                    int id = (int)LoanQueries.UpsertCustomerRequestedLoan(requestedLoan);
                    if (id < 1)
                    {
                        info.AddError("could not save requested loan");
                        return(info);
                    }
                }


//                var session = new CustomerSession() {
//                    CustomerId = customer.Id,
//                    StartSession = now,
//                    Ip = customer.LoginInfo != null ? customer.LoginInfo.RemoteIp ?? "unknown" : "unknown",//TODO: review
//                    IsPasswdOk = true,
//                    ErrorMessage = "Registration" //TODO: do something with this
//                };
//
//                isSuccess = CustomerQueries.SaveCustomerSession(session) ?? true;
//                if (!isSuccess) {
//                    info.AddError("could not save customer session");
//                    return info;
//                }

                if (sourceRefList != null && visitTimeList != null)
                {
                    isSuccess = CustomerQueries.SaveSourceRefHistory(customer.Id, sourceRefList, visitTimeList) ?? true;
                    if (!isSuccess)
                    {
                        info.AddError("could not save customer ref history");
                    }
                }

                if (campaignSrcRef != null)
                {
                    isSuccess = CustomerQueries.SaveCampaignSourceRef(customer.Id, campaignSrcRef);
                    if (!isSuccess)
                    {
                        info.AddError("could not save campaign source ref for customer: " + customer.Id);
                        return(info);
                    }
                }

                if (customer.AlibabaId != null && customer.IsAlibaba)
                {
                    AlibabaBuyer alibabaBuyer = new AlibabaBuyer {
                        AliId      = Convert.ToInt64(customer.AlibabaId),
                        CustomerId = customer.Id
                    };

                    isSuccess = AlibabaQueries.CreateAlibabaBuyer(alibabaBuyer) ?? true;
                    if (!isSuccess)
                    {
                        info.AddError("could not create alibaba buyer");
                    }
                }

                if (customer.CustomerAddress != null)
                {
                    customer.CustomerAddress.CustomerId = customer.Id;
                    isSuccess = CustomerQueries.UpsertCustomerAddress(customer.CustomerAddress) ?? true;
                    if (!isSuccess)
                    {
                        info.AddError("could not save customer address");
                    }
                }

                if (CollectionUtils.IsNotEmpty(addresses))
                {
                    foreach (CustomerAddress customerAddress in addresses)
                    {
                        bool?res = CustomerQueries.UpsertCustomerAddress(customerAddress);
                        if (res == null || res.Value == false)
                        {
                            info.AddError("could not save customer address");
                            return(info);
                        }
                    }
                }

                if (CollectionUtils.IsNotEmpty(phoneNumbers))
                {
                    foreach (CustomerPhone phone in phoneNumbers)
                    {
                        bool saveCustomerPhone = CustomerQueries.SaveCustomerPhone(phone);
                        if (!saveCustomerPhone)
                        {
                            info.AddError("could not save customer phone");
                            return(info);
                        }
                    }
                }

                unitOfWork.Commit();
                return(info);
            }
        }
Beispiel #4
0
        }         // constructor

        public WizardModel BuildWizardModel(
            Customer cus,
            HttpSessionStateBase session,
            string profile,
            string requestUrl,
            bool isProfile
            )
        {
            CustomerOrigin uiOrigin = cus == null?UiCustomerOrigin.Get() : cus.CustomerOrigin;

            var wizardModel = new WizardModel();

            Log.InfoFormat(
                "BuildWizardModel URL: {0} origin {1} customer {2}",
                requestUrl,
                uiOrigin.Name,
                cus == null ? "null" : cus.Id.ToString()
                );

            var customerModel = new CustomerModel {
                loggedIn         = cus != null,
                bankAccountAdded = false,
                Origin           = uiOrigin.Name,
            };

            if (!string.IsNullOrEmpty(profile))
            {
                wizardModel.WhiteLabel     = _whiteLabelProviderRepository.GetByName(profile);
                customerModel.IsWhiteLabel = wizardModel.WhiteLabel != null;
                customerModel.WhiteLabelId = wizardModel.WhiteLabel != null ? wizardModel.WhiteLabel.Id : 0;
            }

            wizardModel.Customer = customerModel;

            if (!customerModel.loggedIn)
            {
                customerModel.IsBrokerFill =
                    (session[Constant.Broker.FillsForCustomer] ?? Constant.No).ToString() == Constant.Yes;

                return(wizardModel);
            }             // if

            if (cus == null)
            {
                return(wizardModel);
            }

            var customer = m_oCustomerRepository.GetAndInitialize(cus.Id);

            if (customer == null)
            {
                return(wizardModel);
            }

            var user = m_oUsers.Get(cus.Id);

            customerModel.Origin = customer.CustomerOrigin.Name;
            customerModel.IsTest = customer.IsTest;

            if (customer.WhiteLabel != null)
            {
                wizardModel.WhiteLabel     = customer.WhiteLabel;
                customerModel.IsWhiteLabel = wizardModel.WhiteLabel != null;
                customerModel.WhiteLabelId = customer.WhiteLabel.Id;
            }             // if

            customerModel.Id         = customer.Id;
            customerModel.RefNumber  = customer.RefNumber;
            customerModel.userName   = user.Name;
            customerModel.Email      = customer.Name;
            customerModel.EmailState = EmailConfirmationState.Get(customer);

            customerModel.CustomerPersonalInfo = customer.PersonalInfo;

            customerModel.IsAlibaba = customer.IsAlibaba;

            if (customer.PropertyStatus != null)
            {
                customerModel.PropertyStatus = new PropertyStatusModel {
                    Id          = customer.PropertyStatus.Id,
                    Description = customer.PropertyStatus.Description,
                    IsOwnerOfOtherProperties = customer.PropertyStatus.IsOwnerOfOtherProperties,
                    IsOwnerOfMainAddress     = customer.PropertyStatus.IsOwnerOfMainAddress
                };
            }
            else
            {
                customerModel.PropertyStatus = new PropertyStatusModel();
            }             // if

            customerModel.BusinessTypeReduced = customerModel.CustomerPersonalInfo == null?
                                                TypeOfBusinessReduced.Personal.ToString() : customer.PersonalInfo.TypeOfBusiness.Reduce().ToString();

            customerModel.mpAccounts   = customer.GetMarketPlaces();
            customerModel.CreditSum    = customer.CreditSum;
            customerModel.CreditResult = customer.CreditResult.ToString();
            customerModel.Status       = customer.Status.ToString();

            var account = new AccountSettingsModel {
                SecurityQuestions = m_oQuestions.GetQuestions(),

                SecurityQuestionModel = new SecurityQuestionModel {
                    Question = user.SecurityQuestion == null ? 0 : user.SecurityQuestion.Id,
                    Answer   = user.SecurityAnswer
                },
            };

            customerModel.AccountSettings = account;

            customerModel.GreetingMailSentDate = customer.GreetingMailSentDate;

            var company = customer.Company;

            customerModel.CanHaveDirectors = false;

            if (company != null)
            {
                customerModel.CanHaveDirectors = company.TypeOfBusiness != TypeOfBusiness.SoleTrader;

                customerModel.CompanyInfo    = CompanyInfoMap.FromCompany(company);
                customerModel.CompanyAddress = company.CompanyAddress.ToArray();

                customerModel.CompanyInfo.Directors.AddRange(
                    m_oExperianDirectors.Find(customer.Id)
                    .Select(ed => DirectorModel.FromExperianDirector(ed, company.TypeOfBusiness.Reduce()))
                    );
            }             // if

            if (customer.AddressInfo != null)
            {
                customerModel.PersonalAddress          = customer.AddressInfo.PersonalAddress.ToArray();
                customerModel.PrevPersonAddresses      = customer.AddressInfo.PrevPersonAddresses.ToArray();
                customerModel.OtherPropertiesAddresses = customer.AddressInfo.OtherPropertiesAddresses.ToArray();
            }             // if

            customerModel.CompanyEmployeeCountInfo = new CompanyEmployeeCountInfo(customer.Company);

            customerModel.CustomerStatusName = customer.CollectionStatus.Name;

            // customerModel.LoyaltyPoints = customer.LoyaltyPoints();
            customerModel.IsOffline  = customer.IsOffline;
            customerModel.IsDisabled = !customer.CollectionStatus.IsEnabled;

            customerModel.LastSavedWizardStep = ((customer.WizardStep == null) || customer.WizardStep.TheLastOne)
                                ? string.Empty
                                : customer.WizardStep.Name;

            customerModel.QuickOffer = BuildQuickOfferModel(customer);

            CustomerRequestedLoan ra = customer.CustomerRequestedLoan.OrderByDescending(x => x.Created).FirstOrDefault();

            customerModel.RequestedLoan = ra ?? new CustomerRequestedLoan();

            customerModel.IsBrokerFill = customer.FilledByBroker;
            customerModel.DefaultCardSelectionAllowed = customer.DefaultCardSelectionAllowed;

            var cr = customer.LastCashRequest;

            customerModel.IsCurrentCashRequestFromQuickOffer = (cr != null) && (cr.QuickOffer != null);

            customerModel.IsLoanDetailsFixed = !m_oChangeLoanDetailsModelBuilder.IsAmountChangingAllowed(cr);

            customerModel.LastCashRequestID = (cr == null) ? 0 : cr.Id;

            if (isProfile)
            {
                BuildProfileModel(customerModel, customer);
            }

            return(wizardModel);
        }         // BuildWizardModel
Beispiel #5
0
 /// <summary>
 /// Saves the customer requested loan.
 /// </summary>
 /// <param name="requestedLoan">The requested loan.</param>
 /// <returns></returns>
 public Optional <int> SaveCustomerRequestedLoan(CustomerRequestedLoan requestedLoan)
 {
     return(LoanQueries.UpsertCustomerRequestedLoan(requestedLoan));
 }