AI OnAI Off
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);
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;
Is there any eg. how to save add/modify StateProvinceRow of the country?