protected void rptrLanguageDivs_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { var txtLocalizedName = (TextBox)e.Item.FindControl("txtLocalizedName"); var lblLanguageId = (Label)e.Item.FindControl("lblLanguageId"); int languageId = int.Parse(lblLanguageId.Text); var content = SpecificationAttributeManager.GetSpecificationAttributeLocalizedBySpecificationAttributeIdAndLanguageId(this.SpecificationAttributeId, languageId); if (content != null) { txtLocalizedName.Text = content.Name; } } }
protected void SaveLocalizableContent(SpecificationAttribute specificationAttribute) { if (specificationAttribute == null) { return; } if (!this.HasLocalizableContent) { return; } foreach (RepeaterItem item in rptrLanguageDivs.Items) { if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) { var txtLocalizedName = (TextBox)item.FindControl("txtLocalizedName"); var lblLanguageId = (Label)item.FindControl("lblLanguageId"); int languageId = int.Parse(lblLanguageId.Text); string name = txtLocalizedName.Text; bool allFieldsAreEmpty = string.IsNullOrEmpty(name); var content = SpecificationAttributeManager.GetSpecificationAttributeLocalizedBySpecificationAttributeIdAndLanguageId(specificationAttribute.SpecificationAttributeId, languageId); if (content == null) { if (!allFieldsAreEmpty && languageId > 0) { //only insert if one of the fields are filled out (avoid too many empty records in db...) content = SpecificationAttributeManager.InsertSpecificationAttributeLocalized(specificationAttribute.SpecificationAttributeId, languageId, name); } } else { if (languageId > 0) { content = SpecificationAttributeManager.UpdateSpecificationAttributeLocalized(content.SpecificationAttributeLocalizedId, content.SpecificationAttributeId, languageId, name); } } } } }