Exemplo n.º 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 EditAddress(ErpCustomerAddress erpCustomerAddress, Customer customer, CommercePipelineExecutionContext context)
        {
            var entityView = new EntityView();

            entityView.EntityId    = customer.Id;
            entityView.ItemId      = customer.Components[2].Id;
            entityView.Name        = "AddressDetails";
            entityView.DisplayName = "Address Details";
            entityView.Action      = "EditAddress";
            entityView.ChildViews  = new List <Model>();
            entityView.DisplayRank = 500;
            entityView.UiHint      = "Flat";
            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         = "Country",
                    DisplayName  = "Country",
                    Value        = erpCustomerAddress.Country,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    IsReadOnly   = true,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                },
                new ViewProperty()
                {
                    Name         = "CountryCode",
                    DisplayName  = "Country Code",
                    Value        = erpCustomerAddress.CountryCode,
                    IsHidden     = true,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    IsReadOnly   = true,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                },
                new ViewProperty()
                {
                    Name         = "AddressName",
                    DisplayName  = "Address Name",
                    Value        = erpCustomerAddress.AddressName,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = true,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "af3a53fe862d4bb190da30b5f9e5b9f7"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "FirstName",
                    DisplayName  = "First Name",
                    Value        = erpCustomerAddress.FirstName,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    IsReadOnly   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "5e4005cba57c4fee97d60db399be02ba"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "LastName",
                    DisplayName  = "Last Name",
                    Value        = erpCustomerAddress.LastName,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    IsReadOnly   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "ad94b1f4f4554e168da7a3d9ae935507"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "Address1",
                    DisplayName  = "Address1",
                    Value        = erpCustomerAddress.Address1,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = true,
                    IsReadOnly   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "59bf5f09efb8495db4b5be8247351a86"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "Address2",
                    DisplayName  = "Address2",
                    Value        = erpCustomerAddress.Address2,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = true,
                    IsReadOnly   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "3dd39459b4d049099fe0cd50762e3267"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "City",
                    DisplayName  = "City",
                    Value        = erpCustomerAddress.City,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    IsReadOnly   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "c4c3217dd6714714b591a46b44bd9360"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "State",
                    DisplayName  = "State",
                    Value        = erpCustomerAddress.State,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    IsReadOnly   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 50,
                            Models         = new List <Model>(),
                            PolicyId       = "50cf776c3082414ba7d036e6ff387e23"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "StateCode",
                    DisplayName  = "State Code",
                    Value        = erpCustomerAddress.StateCode,
                    IsHidden     = true,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    IsReadOnly   = true,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                },
                new ViewProperty()
                {
                    Name         = "ZipPostalCode",
                    DisplayName  = "Zip/Postal Code",
                    Value        = erpCustomerAddress.ZipPostalCode,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    IsReadOnly   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "f6267895a15442938fdb156ac54c730a"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "IsPrimary",
                    DisplayName  = "IsPrimary",
                    Value        = erpCustomerAddress.IsPrimary.ToString(),
                    IsHidden     = false,
                    OriginalType = "System.Boolean",
                    IsRequired   = true,
                    IsReadOnly   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                },
                new ViewProperty()
                {
                    Name         = "PhoneNumber",
                    DisplayName  = "Phone",
                    Value        = erpCustomerAddress.PhoneNumber,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    IsReadOnly   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 50,
                            Models         = new List <Model>(),
                            PolicyId       = "07a47a75dda0433e9f2bfcccceadb6aa"
                        }
                    }
                }
            };

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