Example #1
0
        protected void SaveLocalizableContent(SpecificationAttributeOption sao)
        {
            if (sao == null)
            {
                return;
            }

            if (!this.HasLocalizableContent)
            {
                return;
            }

            foreach (GridViewRow row in grdSpecificationAttributeOptions.Rows)
            {
                Repeater rptrLanguageDivs2 = row.FindControl("rptrLanguageDivs2") as Repeater;
                if (rptrLanguageDivs2 != null)
                {
                    HiddenField hfSpecificationAttributeOptionId = row.FindControl("hfSpecificationAttributeOptionId") as HiddenField;
                    int         saoId = int.Parse(hfSpecificationAttributeOptionId.Value);
                    if (saoId == sao.SpecificationAttributeOptionId)
                    {
                        foreach (RepeaterItem item in rptrLanguageDivs2.Items)
                        {
                            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                            {
                                var txtLocalizedOptionName = (TextBox)item.FindControl("txtLocalizedOptionName");
                                var lblLanguageId          = (Label)item.FindControl("lblLanguageId");

                                int    languageId = int.Parse(lblLanguageId.Text);
                                string name       = txtLocalizedOptionName.Text;

                                bool allFieldsAreEmpty = string.IsNullOrEmpty(name);

                                var content = SpecificationAttributeManager.GetSpecificationAttributeOptionLocalizedBySpecificationAttributeOptionIdAndLanguageId(sao.SpecificationAttributeOptionId, 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.InsertSpecificationAttributeOptionLocalized(sao.SpecificationAttributeOptionId,
                                                                                                                            languageId, name);
                                    }
                                }
                                else
                                {
                                    if (languageId > 0)
                                    {
                                        content = SpecificationAttributeManager.UpdateSpecificationAttributeOptionLocalized(content.SpecificationAttributeOptionLocalizedId,
                                                                                                                            content.SpecificationAttributeOptionId, languageId, name);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }