FOR EACH row in the spreadsheet (each address), Kentico will check to see if the address already exists within the specific site that the upload is done for. This check will be done by comparing the “Address Line” and “Address Line 2” fields in Kentico with the corresponding columns in the upload spreadsheet. IF the address DOES NOT already exist: Kentico will create the address on the site, populate the address' fields corresponding to the data present in the upload spreadsheet, and assign the address to the users selected by the Admin.
protected void CreateCustomerAddress(int customerID, UserDto userDto){
var country = FindCountry(userDto.Country);
if (country == null)
{
EventLogProvider.LogInformation(@@);
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();
if (address == null)
{
var newAddress = new AddressInfo
{
AddressName = string.Join(@, @, addressNameFields),
AddressLine1 = userDto.AddressLine ?? @@,
AddressLine2 = userDto.AddressLine2,
AddressCity = userDto.City ?? @@,
AddressZip = userDto.PostalCode ?? @@,
AddressPersonalName = userDto.ContactName ?? $@{userDto.FirstName} {userDto.LastName}@,
AddressPhone = userDto.PhoneNumber ?? @@,
AddressCustomerID = customerID,
AddressCountryID = country.CountryID,
AddressStateID = state?.StateID ?? 0,
};
newAddress.SetValue(@AddressType@, AddressType.Shipping.Code);
newAddress.SetValue(@Email@, userDto.Email);
newAddress.SetValue(@CompanyName@, userDto.Company);
newAddress.SetValue(@Status@, @1@);
AddressInfoProvider.SetAddressInfo(newAddress);
}
else{var newAddress = new AddressInfo
{
AddressName = string.Join(@, @, addressNameFields),
AddressLine1 = userDto.AddressLine ?? @@,
AddressLine2 = userDto.AddressLine2,
AddressCity = userDto.City ?? @@,
AddressZip = userDto.PostalCode ?? @@,
AddressPersonalName = userDto.ContactName ?? $@{userDto.FirstName} {userDto.LastName}@,
AddressPhone = userDto.PhoneNumber ?? @@,
AddressCustomerID = customerID,
AddressCountryID = country.CountryID,
AddressStateID = state?.StateID ?? 0,
};
newAddress.SetValue(@AddressType@, AddressType.Shipping.Code);
newAddress.SetValue(@Email@, userDto.Email);
newAddress.SetValue(@CompanyName@, userDto.Company);
newAddress.SetValue(@Status@, @1@);
AddressInfoProvider.SetAddressInfo(newAddress);
}}
↧