Пример #1
0
        private ErpCustomer GetCustomersFromFlatFile(JobConnection argJobConnection)
        {
            var erpCustomerAddress = new ErpCustomerAddress()
            {
                Address1      = "1234 xyz street",
                Address2      = string.Empty,
                AddressName   = "my address",
                City          = "Dublin",
                Company       = "1",
                Country       = "USA",
                CountryCode   = "US",
                IsPrimary     = true,
                PhoneNumber   = "9999999999",
                State         = "Ohio",
                StateCode     = "OH",
                ZipPostalCode = "43034",
                Email         = "*****@*****.**"
            };
            var erpCustomerAddressList = new List <ErpCustomerAddress>();

            erpCustomerAddressList.Add(erpCustomerAddress);
            var erpCustomer = new ErpCustomer()
            {
                AccountNumber          = "0002",
                AccountStatus          = "Active",
                Email                  = "*****@*****.**",
                ErpCustomerAddressList = erpCustomerAddressList,
                FirstName              = "Test",
                LastName               = "Test",
            };

            return(erpCustomer);
        }
        private IList <ErpCustomer> GetCustomersFromERP(JobInfoArgument jobInfoArgument)
        {
            var connectionString = jobInfoArgument.JobConnection.GetPolicy <JobConnectionPolicy>().DbConnectionString;

            Condition.Requires(connectionString).IsNotNullOrEmpty("GetCustomersFromERP: connectionString cannot be null or empty.");
            Condition.Requires(jobInfoArgument.Job.SqlQuery).IsNotNullOrEmpty("GetCustomersFromERP: Job.SqlQuery cannot be null or empty.");
            var customerList = new List <ErpCustomer>();

            using (var sqlConnection = new SqlConnection(connectionString))
            {
                sqlConnection.Open();
                var query = jobInfoArgument.Job.SqlQuery;

                using (var command = new SqlCommand(query, sqlConnection))
                {
                    command.CommandTimeout = 90;
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        var erpCustomerAddress = new ErpCustomerAddress()
                        {
                            Address1      = reader.GetString(reader.GetOrdinal("Address1")),
                            Address2      = reader.GetString(reader.GetOrdinal("Address2")),
                            AddressName   = reader.GetString(reader.GetOrdinal("AddressName")),
                            FirstName     = reader.GetString(reader.GetOrdinal("AddressFirstName")),
                            LastName      = reader.GetString(reader.GetOrdinal("AddressLastName")),
                            City          = reader.GetString(reader.GetOrdinal("City")),
                            Company       = reader.GetString(reader.GetOrdinal("Company")),
                            Country       = reader.GetString(reader.GetOrdinal("Country")),
                            CountryCode   = reader.GetString(reader.GetOrdinal("CountryCode")),
                            IsPrimary     = reader.GetBoolean(reader.GetOrdinal("IsPrimary")),
                            PhoneNumber   = reader.GetString(reader.GetOrdinal("PhoneNumber")),
                            State         = reader.GetString(reader.GetOrdinal("State")),
                            StateCode     = reader.GetString(reader.GetOrdinal("StateCode")),
                            ZipPostalCode = reader.GetString(reader.GetOrdinal("ZipCode")),
                            Email         = reader.GetString(reader.GetOrdinal("Email"))
                        };
                        var erpCustomerAddressList = new List <ErpCustomerAddress>
                        {
                            erpCustomerAddress
                        };
                        var erpCustomer = new ErpCustomer()
                        {
                            AccountNumber          = reader.GetString(reader.GetOrdinal("CustomerAccountNumber")),
                            AccountStatus          = reader.GetString(reader.GetOrdinal("CustomerAccountStatus")),
                            Email                  = reader.GetString(reader.GetOrdinal("CustomerEmail")),
                            PhoneNumber            = reader.GetString(reader.GetOrdinal("CustomerPhoneNumber")),
                            FirstName              = reader.GetString(reader.GetOrdinal("CustomerFirstName")),
                            LastName               = reader.GetString(reader.GetOrdinal("CustomerLastName")),
                            ErpCustomerAddressList = erpCustomerAddressList
                        };
                        customerList.Add(erpCustomer);
                    }
                }
            }
            return(customerList);
        }
        private async Task EditCustomer(ErpCustomer erpCustomer, Customer customer, CommercePipelineExecutionContext context)
        {
            var entityView = new EntityView();

            entityView.EntityId    = customer.Id;
            entityView.Name        = "Details";
            entityView.DisplayName = "Details";
            entityView.Action      = "EditCustomer";
            entityView.ChildViews  = new List <Model>();
            entityView.DisplayRank = 500;
            entityView.UiHint      = "Flat";
            entityView.Icon        = "chart_column_stacked";
            entityView.Properties  = new List <ViewProperty>()
            {
                new ViewProperty()
                {
                    Name         = "Version",
                    DisplayName  = "Version",
                    Value        = customer.Version.ToString(),
                    IsHidden     = true,
                    OriginalType = "System.Int32",
                    IsRequired   = true,
                    IsReadOnly   = true,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                },
                new ViewProperty()
                {
                    Name         = "FirstName",
                    DisplayName  = "First Name",
                    Value        = erpCustomer.FirstName,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "e9150513558d4ba080accc7fa84fad00"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "LastName",
                    DisplayName  = "Last Name",
                    Value        = erpCustomer.LastName,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "70fdc77e288143c5ae050fe171ffffd3"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "Email",
                    DisplayName  = "Email",
                    Value        = erpCustomer.Email,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = true,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "960bae42b5084ae48b3c0770260587aa"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "AccountStatus",
                    DisplayName  = "Account Status",
                    Value        = erpCustomer.AccountStatus,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = true,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new AvailableSelectionsPolicy()
                        {
                            Models           = new List <Model>(),
                            PolicyId         = "3250891c884c4ba08c5fff2835cdc914",
                            AllowMultiSelect = false,
                            List             = new List <Selection>()
                            {
                                new Selection()
                                {
                                    Name        = "ActiveAccount",
                                    Policies    = new List <Policy>(),
                                    DisplayName = "Active",
                                    IsDefault   = false
                                },
                                new Selection()
                                {
                                    Name        = "InactiveAccount",
                                    Policies    = new List <Policy>(),
                                    DisplayName = "Inactive",
                                    IsDefault   = false
                                },
                                new Selection()
                                {
                                    Name        = "RequiresApproval",
                                    Policies    = new List <Policy>(),
                                    DisplayName = "Requires Approval",
                                    IsDefault   = false
                                }
                            }
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "PhoneNumber",
                    DisplayName  = "Phone",
                    Value        = erpCustomer.PhoneNumber,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = true,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 50,
                            Models         = new List <Model>(),
                            PolicyId       = "30b9ad5b9e014b3a8697967280cd2596"
                        }
                    }
                }
                //new ViewProperty()
                //{
                //    Name = "Language",
                //    DisplayName = "Language",
                //    Value = "en",
                //    IsHidden = false,
                //    OriginalType = "System.String",
                //    IsRequired = true,
                //    UiType = string.Empty,
                //    Policies = new List<Policy>()
                //    {
                //        new AvailableSelectionsPolicy()
                //        {
                //            Models = new List<Model>(),
                //            PolicyId = "beaebd811a8747db8b0577c4165f4118",
                //            AllowMultiSelect = false,
                //            List = new List<Selection>()
                //            {
                //                new Selection()
                //                {
                //                    Name = "en",
                //                    Policies = new List<Policy>(),
                //                    DisplayName = "en",
                //                    IsDefault = false
                //                },
                //                new Selection()
                //                {
                //                    Name = "de-DE",
                //                    Policies = new List<Policy>(),
                //                    DisplayName = "de-DE",
                //                    IsDefault = false
                //                },
                //                new Selection()
                //                {
                //                    Name = "fr-FR",
                //                    Policies = new List<Policy>(),
                //                    DisplayName = "fr-FR",
                //                    IsDefault = false
                //                }
                //            }
                //        }
                //    }
                //}
            };

            var viewCustomer = await _doActionPipeline.Run(entityView, context);

            foreach (var erpCustomerAddress in erpCustomer.ErpCustomerAddressList)
            {
                await EditAddress(erpCustomerAddress, customer, context);
            }
        }