0

我第一次看到这个。这是我所拥有的

我从会话中获得客户,这里我的国家代码是 2 个字母代码

var selCustomer = SessionService.GetItem<Customer>(SessionKeys.SelectedCustomer);

我需要将 2 个字母的国家代码转换为 3 个字母的国家代码以用于非常具体的用途

var customerAddress = GeographyServiceInstance.FixAddresss(selCustomer.CustomerAddress, true);

在这个阶段,当我检查信息时,selCustomer.CustomerAddress、customerAddress 甚至会话中的客户都更改为 3 个字母代码。我没有在这里设置会话,那为什么会被覆盖?

我能够在 session 和 selCustomer.CustomerAddress 没有被覆盖的情况下做到这一点的唯一方法是

var customer = 
    SessionService.GetItem<Customer>(SessionKeys.SelectedCustomer);

// turn customer address into 3 letter country code, 
// hard way, otherwise original object and session 
// address are being overwritten
Address customerAddress = null;
if (customer.CustomerAddress != null)
{
    customerAddress = new Address
    {
        AddressId = customer.CustomerAddress.AddressId,
        AddressLine1 = customer.CustomerAddress.AddressLine1,
        AddressLine2 = customer.CustomerAddress.AddressLine2,
        City = customer.CustomerAddress.City,
        CountryCode = customer.CustomerAddress.CountryCode,
        CountryInfo = customer.CustomerAddress.CountryInfo,
        StateCode = customer.CustomerAddress.StateCode,
        StateInfo = customer.CustomerAddress.StateInfo
    };
}
customerAddress =
    GeographyServiceInstance.FixAddress(customerAddress, true);
4

0 回答 0