Esempio n. 1
0
        protected void SaveLocalizableContent(ProductAttribute productAttribute)
        {
            if (productAttribute == 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 txtLocalizedDescription = (TextBox)item.FindControl("txtLocalizedDescription");
                    var lblLanguageId           = (Label)item.FindControl("lblLanguageId");

                    int    languageId  = int.Parse(lblLanguageId.Text);
                    string name        = txtLocalizedName.Text;
                    string description = txtLocalizedDescription.Text;

                    bool allFieldsAreEmpty = (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(description));

                    var content = ProductAttributeManager.GetProductAttributeLocalizedByProductAttributeIdAndLanguageId(productAttribute.ProductAttributeId, 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 = ProductAttributeManager.InsertProductAttributeLocalized(productAttribute.ProductAttributeId,
                                                                                              languageId, name, description);
                        }
                    }
                    else
                    {
                        if (languageId > 0)
                        {
                            content = ProductAttributeManager.UpdateProductAttributeLocalized(content.ProductAttributeLocalizedId, content.ProductAttributeId,
                                                                                              languageId, name, description);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        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 txtLocalizedDescription = (TextBox)e.Item.FindControl("txtLocalizedDescription");
                var lblLanguageId           = (Label)e.Item.FindControl("lblLanguageId");

                int languageId = int.Parse(lblLanguageId.Text);

                var content = ProductAttributeManager.GetProductAttributeLocalizedByProductAttributeIdAndLanguageId(this.ProductAttributeId, languageId);

                if (content != null)
                {
                    txtLocalizedName.Text        = content.Name;
                    txtLocalizedDescription.Text = content.Description;
                }
            }
        }