public CountryAndState GetCountryState(string Country, string State) { CountryAndState cas = new CountryAndState(); Countryconst ct; Stateconst st; /// Get the country ct = db.Query <Countryconst>("select first 1 * from countryconst where UPPER(abbreviation) containing UPPER(@abb) or UPPER(name) containing UPPER(@n) ", new { n = Country, abb = Country.Truncate(10) }).FirstOrDefault(); // If we have no country, lookup just by state if (ct == null || ct.ID == null) { st = db.Query <Stateconst>("select first 1 * from stateconst where UPPER(name) containing UPPER(@st) or UPPER(code) containing UPPER(@abb) ", new { st = State, abb = State.Truncate(21) }).FirstOrDefault(); } else // If we have a country, include that in the lookup { st = db.Query <Stateconst>("select first 1 * from stateconst where UPPER(name) containing UPPER(@st) or UPPER(code) containing UPPER(@abb) and countryconstid = @cid ", new { st = State, abb = State.Truncate(21), cid = ct.ID }).FirstOrDefault(); } // If we have a state and no country if (st != null && ct == null) { // Lookup the country ct = db.Query <Countryconst>("select first 1 * from countryconst where id = @cid", new { cid = st.COUNTRYCONSTID }).FirstOrDefault(); } if (st == null || ct == null) { throw new Exception("Cant find Country and Or State. [" + Country + "] [" + State + "] "); } cas.State = st; cas.Country = ct; return(cas); }
public static Customer MapCustomer(Config cfg, ZCOrder o, String customerName, CountryAndState csa) { Customer customer = new Customer(); customer.CustomerID = "-1"; customer.Status = "Normal"; customer.TaxRate = null; customer.Name = customerName; customer.CreditLimit = "0"; customer.TaxExempt = false; customer.TaxExemptNumber = null; customer.TaxExemptSpecified = true; customer.ActiveFlag = true; customer.ActiveFlagSpecified = true; customer.AccountingID = null; customer.JobDepth = "1"; Address address = new Address(); address.Street = o.customers_street_address; address.Name = o.customers_name; address.Attn = address.Name; address.Residential = false; address.ResidentialSpecified = false; address.State.Code = csa.State.CODE; address.State.Name = csa.State.NAME; address.Country.Name = csa.Country.NAME; address.Country.Code = csa.Country.ABBREVIATION; address.Country.ID = csa.Country.ID.ToString(); address.Zip = o.customers_postcode; address.Type = "Main Office"; address.TempAccount = null; address.Default = true; address.DefaultSpecified = true; address.AddressInformationList = new List <AddressInformation>() { new AddressInformation() { Name = "Email", Type = "Email", Default = true, DefaultSpecified = true, Data = o.customers_email_address.ToString() } }; customer.Addresses.Add(address); return(customer); }