WHEN an Admin uploads the excel file to Kentico, 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.
I want to be able to use this upload new addresses' in Kentico, but also to modify/update Addresses' and their information at the same time.In the below code existing address working fine, but new address I upload means not working. 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);
↧