How to save new state for country using StateProvinceRow ?

Vote:
 

Is there any eg. how to save add/modify StateProvinceRow of the country?

#150663
Jun 27, 2016 11:53
Vote:
 

Hi,

You can simply load the CountryDto, then add new row to the StateProvince table. Here's an example:

CountryDto.StateProvinceRow spRow = (from reg in CountryDto.StateProvince
where reg.RowState != DataRowState.Deleted && 
String.Compare(reg.Name, name, StringComparison.CurrentCultureIgnoreCase) == 0
select reg).FirstOrDefault();
if (spRow == null)
{
spRow = CountryDto.StateProvince.NewStateProvinceRow();
spRow.CountryId = CountryId;
}

spRow.Name = name;
spRow.Ordering = Int32.Parse(e.Item[_GridOrderingString].ToString());
spRow.Visible = Boolean.Parse(e.Item[_GridVisibleString].ToString());

if (spRow.RowState == DataRowState.Detached)
CountryDto.StateProvince.Rows.Add(spRow);

CountryManager.Save(CountryDto);



#150876
Jul 01, 2016 9:38
Vote:
 

Hi,

thank you for reply.

It helped partially. Although I used the code above, I had to update country Id for all existed stated and the next code was used before saving:

countryDto.EnforceConstraints = false;

if (countryDto.HasChanges())

{

if (countryDto.Country.Rows.Count > 0)

{

var countryId = countryDto.Country[0].CountryId;

foreach (CountryDto.StateProvinceRowstateProvinceRow1in countryDto.StateProvince.Rows)

{

stateProvinceRow1.CountryId = countryId;

}

}

}

countryDto.EnforceConstraints = true;

#150878
Jul 01, 2016 9:44
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.