Exemple #1
0
        public override void Execute()
        {
            // check this customer is Alibaba's member also
            var          aliMemberRep = ObjectFactory.GetInstance <AlibabaBuyerRepository>();
            AlibabaBuyer aliMember    = aliMemberRep.ByCustomer(CustomerID);

            if (aliMember == null)
            {
                Log.Alert("Alibaba customer {0} not found in AlibabaBuyer table", CustomerID);
                return;
            }

            Log.Info(string.Format("DATASHARING1*************{0}*******************", aliMember.AliId));

            if (aliMember.Customer.Id != CustomerID || aliMember.AliId == 0)
            {
                Log.Info("Alibaba member for customer {0} not exists OR customer business Type not supported in Alibaba (Entrepreneur|SoleTrader|None)", CustomerID);
                return;
            }

            // check if 001 exists before 002
            if (businessType == AlibabaBusinessType.APPLICATION_REVIEW)
            {
                var exists001 = this.sentDataRep.GetAll().FirstOrDefault(c => (c.AlibabaBuyer.Id == aliMember.Id && c.Customer.Id == CustomerID && c.BizTypeCode == AlibabaBusinessType.APPLICATION.DescriptionAttr()));

                // create 001 fisrt
                if (exists001 == null || exists001.Id == 0)
                {
                    DB.FillFirst(
                        Result,
                        "AlibabaCustomerDataSharing",
                        CommandSpecies.StoredProcedure,
                        new QueryParameter("CustomerID", this.CustomerID),
                        new QueryParameter("FinalDecision", 0)
                        );

                    SendRequest(aliMember, this.Result, AlibabaBusinessType.APPLICATION);
                }
            }
            Result = new CustomerDataSharing();
            DB.FillFirst(
                Result,
                "AlibabaCustomerDataSharing",
                CommandSpecies.StoredProcedure,
                new QueryParameter("CustomerID", CustomerID),
                new QueryParameter("FinalDecision", (businessType == AlibabaBusinessType.APPLICATION_REVIEW)?1:0)
                );

            Log.Debug("**********DATASHARING4 strategy, execute customerID: {0}, finalDecision: {1}, Result: {2}", CustomerID, this.businessType.DescriptionAttr(), JsonConvert.SerializeObject(Result, jf));

            if (Result == null || Result.aliMemberId == 0 || Result.aId == "0")
            {
                Log.Info("Relevant data for sharing with Alibaba (001/002) for customer {0}, aliId {1} not found", CustomerID, aliMember.AliId);
                return;
            }

            SendRequest(aliMember, Result, businessType);
        }
Exemple #2
0
        public bool?CreateAlibabaBuyer(AlibabaBuyer alibabaBuyer)
        {
            using (var sqlConnection = GetOpenedSqlConnection()) {
                var cmd = GetInsertCommand(alibabaBuyer, sqlConnection, Tables.AlibabaBuyer);
                if (!cmd.HasValue)
                {
                    return(null);
                }

                using (var sqlCommand = cmd.GetValue()) {
                    return(ExecuteNonQueryAndLog(sqlCommand));
                }
            }
        }
Exemple #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);
            }
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="aliMember"></param>
        /// <param name="result"></param>
        /// <param name="bizType"></param>
        private void SendRequest(AlibabaBuyer aliMember, CustomerDataSharing result, AlibabaBusinessType bizType)
        {
            if (result == null)
            {
                return;
            }
            if (aliMember == null)
            {
                return;
            }
            if (result.aliMemberId == 0)
            {
                return;
            }
            if (string.IsNullOrEmpty(result.aId))
            {
                return;
            }

            try {
                AlibabaClient client;

                if (CurrentValues.Instance.AlibabaClientEnvironment != null && CurrentValues.Instance.AlibabaClientEnvironment.Value.Contains("Sandbox"))
                {
                    client = new AlibabaClient(CurrentValues.Instance.AlibabaBaseUrl_Sandbox, CurrentValues.Instance.AlibabaUrlPath_Sandbox, CurrentValues.Instance.AlibabaAppSecret_Sandbox);
                }
                else
                {
                    client = new AlibabaClient(CurrentValues.Instance.AlibabaBaseUrl, CurrentValues.Instance.AlibabaUrlPath, CurrentValues.Instance.AlibabaAppSecret);
                }

                IRestResponse response = client.SendDecision(JObject.FromObject(result, new JsonSerializer {
                    DateParseHandling = DateParseHandling.None
                }), bizType);

                AlibabaSentData sent = new AlibabaSentData();
                sent.AlibabaBuyer = aliMember;
                sent.Customer     = sent.AlibabaBuyer.Customer;
                sent.Request      = JsonConvert.SerializeObject(response.Request.Parameters);
                sent.Response     = response.Content;

                var jsonContent = JsonConvert.DeserializeObject(response.Content);
                var objContent  = JObject.Parse(jsonContent.ToString());

                var errCode = objContent.Properties().FirstOrDefault(c => c.Name == "errCode");
                if (errCode != null)
                {
                    sent.ErrorCode = errCode.Value.ToString();
                }

                var errMsg = objContent.Properties().FirstOrDefault(c => c.Name == "errMsg");
                if (errMsg != null)
                {
                    sent.ErrorMessage = errMsg.Value.ToString();
                }

                var signature = response.Request.Parameters.FirstOrDefault(p => p.Name == "_aop_signature");
                if (signature != null)
                {
                    sent.Signature = signature.Value.ToString();
                }

                var btype = objContent.Properties().FirstOrDefault(c => c.Name == "bizType");
                if (btype != null)
                {
                    sent.BizTypeCode = btype.Value.ToString();
                }

                //Add comments
                switch (bizType)
                {
                case AlibabaBusinessType.APPLICATION_WS_3:
                    sent.Comments = "DataSharing Step 3";
                    break;

                case AlibabaBusinessType.APPLICATION:
                    sent.Comments = "DataSharing Wizard Complete";
                    break;
                }

                sent.StatusCode = response.StatusCode.DescriptionAttr();
                sent.SentDate   = DateTime.UtcNow;
                this.sentDataRep.Save(sent);
            } catch (HttpException e) {
                throw new StrategyAlert(this, string.Format("HttpException: Failed to transmit for customer {0}, CustomerDataSharing: {1}, alimember:{2}", CustomerID, result.Stringify(), aliMember.AliId), e);
            } catch (Exception ex) {
                throw new StrategyAlert(this, string.Format("Failed to transmit for customer {0}, CustomerDataSharing: {1}, alimember:{2}", CustomerID, result.Stringify(), aliMember.AliId), ex);
            }
        }