protected void CreateCustomerAddress(int customerID, UserDto userDto)
{
var country = FindCountry(userDto.Country);
if (country == null)
{
EventLogProvider.LogInformation("Import users", "INFO", $"Skipping creation of address of user { userDto.Email }. Reason - invalid country.");
return;
}
var state = FindState(userDto.State, country.CountryID);
var addressNameFields = new[] { $"{userDto.FirstName} {userDto.LastName}", userDto.AddressLine, userDto.AddressLine2, userDto.City }
.Where(af => !string.IsNullOrWhiteSpace(af));
AddressInfo address = AddressInfoProvider.GetAddresses()
.WhereEquals("AddressCustomerID", customerID)
.FirstOrDefault();
AddressInfo address = AddressInfoProvider.GetAddresses()
.WhereEquals("AddressCustomerID", customerID )
.FirstOrDefault();
if (address == null)
{
address = new AddressInfo();
address.AddressName = string.Join(", ", addressNameFields);
address.AddressCustomerID = customerID;
address.AddressLine1 = userDto.AddressLine;
address.AddressLine2 = userDto.AddressLine2;
address.AddressZip = userDto.PostalCode;
address.AddressCity = userDto.City;
address.AddressCountryID = country.CountryID;
address.AddressStateID = state.StateID;
address.AddressPhone = userDto.PhoneNumber;
address.AddressPersonalName = userDto.ContactName ?? $"{userDto.FirstName} {userDto.LastName}";
address.SetValue("Email", userDto.Email);
address.SetValue("CompanyName", userDto.Company);
address.SetValue("Status", "1");
address.SetValue("AddressType", AddressType.Shipping.Code);
}
else
{
address.AddressName = string.Join(", ", addressNameFields);
address.AddressCustomerID = customerID;
address.AddressLine1 = userDto.AddressLine;
address.AddressLine2 = userDto.AddressLine2;
address.AddressZip = userDto.PostalCode;
address.AddressCity = userDto.City;
address.AddressCountryID = country.CountryID;
address.AddressStateID = state.StateID;
address.AddressPhone = userDto.PhoneNumber;
address.AddressPersonalName = userDto.ContactName ?? $"{userDto.FirstName} {userDto.LastName}";
address.SetValue("Email", userDto.Email);
address.SetValue("CompanyName", userDto.Company);
address.SetValue("Status", "1");
address.SetValue("AddressType", AddressType.Shipping.Code);
}
AddressInfoProvider.SetAddressInfo(address);