/// <summary>
        /// Gets a specification attribute option
        /// </summary>
        /// <param name="SpecificationAttributeOptionID">The specification attribute option identifier</param>
        /// <returns>Specification attribute option</returns>
        public static SpecificationAttributeOption GetSpecificationAttributeOptionByID(int specificationAttributeOptionID)
        {
            if (specificationAttributeOptionID == 0)
            {
                return(null);
            }

            string key  = string.Format(SPECIFICATIONATTRIBUTEOPTION_BY_ID_KEY, specificationAttributeOptionID);
            object obj2 = NopCache.Get(key);

            if (SpecificationAttributeManager.CacheEnabled && (obj2 != null))
            {
                return((SpecificationAttributeOption)obj2);
            }

            DBSpecificationAttributeOption dbItem = DBProviderManager <DBSpecificationAttributeProvider> .Provider.GetSpecificationAttributeOptionByID(specificationAttributeOptionID);

            SpecificationAttributeOption specificationAttribute = DBMapping(dbItem);

            if (SpecificationAttributeManager.CacheEnabled)
            {
                NopCache.Max(key, specificationAttribute);
            }
            return(specificationAttribute);
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                var specificationAttribute = this.SpecificationAttributeService.GetSpecificationAttributeById(this.SpecificationAttributeId);
                if (specificationAttribute != null)
                {
                    var sao = new SpecificationAttributeOption()
                    {
                        SpecificationAttributeId= specificationAttribute.SpecificationAttributeId,
                        Name= txtNewOptionName.Text,
                        DisplayOrder= txtNewOptionDisplayOrder.Value
                    };
                    this.SpecificationAttributeService.InsertSpecificationAttributeOption(sao);

                    SaveLocalizableContent(sao);

                    string url = string.Format("SpecificationAttributeDetails.aspx?SpecificationAttributeID={0}&TabID={1}", specificationAttribute.SpecificationAttributeId, "pnlOptions");
                    Response.Redirect(url);
                }
            }
            catch (Exception exc)
            {
                processAjaxError(exc);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Updates the specification attribute
        /// </summary>
        /// <param name="specificationAttributeOption">The specification attribute option</param>
        public void UpdateSpecificationAttributeOptions(SpecificationAttributeOption specificationAttributeOption)
        {
            if (specificationAttributeOption == null)
            {
                throw new ArgumentNullException("specificationAttributeOption");
            }

            specificationAttributeOption.Name = CommonHelper.EnsureNotNull(specificationAttributeOption.Name);
            specificationAttributeOption.Name = CommonHelper.EnsureMaximumLength(specificationAttributeOption.Name, 500);


            if (!_context.IsAttached(specificationAttributeOption))
            {
                _context.SpecificationAttributeOptions.Attach(specificationAttributeOption);
            }

            _context.SaveChanges();

            if (this.CacheEnabled)
            {
                _cacheManager.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                _cacheManager.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                _cacheManager.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_PATTERN_KEY);
            }
        }
        /// <summary>
        /// Updates the specification attribute
        /// </summary>
        /// <param name="specificationAttributeOptionID">The specification attribute option identifier</param>
        /// <param name="specificationAttributeID">The specification attribute identifier</param>
        /// <param name="name">The name</param>
        /// <param name="displayOrder">Display order</param>
        /// <returns>Specification attribute option</returns>
        public static SpecificationAttributeOption UpdateSpecificationAttributeOptions(int specificationAttributeOptionID, int specificationAttributeID, string name, int displayOrder)
        {
            DBSpecificationAttributeOption dbItem = DBProviderManager <DBSpecificationAttributeProvider> .Provider.UpdateSpecificationAttributeOption(specificationAttributeOptionID, specificationAttributeID, name, displayOrder);

            SpecificationAttributeOption specificationAttributeOption = DBMapping(dbItem);

            if (SpecificationAttributeManager.CacheEnabled)
            {
                NopCache.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                NopCache.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                NopCache.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_PATTERN_KEY);
            }

            return(specificationAttributeOption);
        }
        /// <summary>
        /// Maps a DBSpecificationAttributeOption to a SpecificationAttributeOption
        /// </summary>
        /// <param name="dbItem">DBSpecificationAttributeOption</param>
        /// <returns>SpecificationAttributeOption</returns>
        private static SpecificationAttributeOption DBMapping(DBSpecificationAttributeOption dbItem)
        {
            if (dbItem == null)
            {
                return(null);
            }

            SpecificationAttributeOption item = new SpecificationAttributeOption();

            item.SpecificationAttributeOptionID = dbItem.SpecificationAttributeOptionID;
            item.SpecificationAttributeID       = dbItem.SpecificationAttributeID;
            item.Name         = dbItem.Name;
            item.DisplayOrder = dbItem.DisplayOrder;

            return(item);
        }
        /// <summary>
        /// Maps a DBSpecificationAttributeOptionCollection to a SpecificationAttributeOptionCollections
        /// </summary>
        /// <param name="dbCollection">DBSpecificationAttributeOptionCollection</param>
        /// <returns>SpecificationAttributeOptionCollection</returns>
        private static SpecificationAttributeOptionCollection DBMapping(DBSpecificationAttributeOptionCollection dbCollection)
        {
            if (dbCollection == null)
            {
                return(null);
            }

            SpecificationAttributeOptionCollection collection = new SpecificationAttributeOptionCollection();

            foreach (DBSpecificationAttributeOption dbItem in dbCollection)
            {
                SpecificationAttributeOption item = DBMapping(dbItem);
                collection.Add(item);
            }

            return(collection);
        }
        protected void SaveLocalizableContentGrid(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);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        protected void SaveLocalizableContent(SpecificationAttributeOption sao)
        {
            if (sao == null)
                return;

            if (!this.HasLocalizableContent)
                return;

            foreach (RepeaterItem item in rptrLanguageDivs.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    var txtNewLocalizedOptionName = (TextBox)item.FindControl("txtNewLocalizedOptionName");
                    var lblLanguageId = (Label)item.FindControl("lblLanguageId");

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

                    bool allFieldsAreEmpty = string.IsNullOrEmpty(name);

                    var content = this.SpecificationAttributeService.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 = new SpecificationAttributeOptionLocalized()
                            {
                                SpecificationAttributeOptionId = sao.SpecificationAttributeOptionId,
                                LanguageId = languageId,
                                Name = name
                            };
                            this.SpecificationAttributeService.InsertSpecificationAttributeOptionLocalized(content);
                        }
                    }
                    else
                    {
                        if (languageId > 0)
                        {
                            content.LanguageId = languageId;
                            content.Name= name;
                            this.SpecificationAttributeService.UpdateSpecificationAttributeOptionLocalized(content);
                        }
                    }
                }
            }
        }