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

            SpecificationAttribute item = new SpecificationAttribute();

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

            return(item);
        }
        /// <summary>
        /// Updates the specification attribute
        /// </summary>
        /// <param name="specificationAttributeID">The specification attribute identifier</param>
        /// <param name="name">The name</param>
        /// <param name="displayOrder">Display order</param>
        /// <returns>Specification attribute</returns>
        public static SpecificationAttribute UpdateSpecificationAttribute(int specificationAttributeID, string name, int displayOrder)
        {
            DBSpecificationAttribute dbItem = DBProviderManager <DBSpecificationAttributeProvider> .Provider.UpdateSpecificationAttribute(specificationAttributeID, name, displayOrder);

            SpecificationAttribute specificationAttribute = DBMapping(dbItem);

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

            return(specificationAttribute);
        }
        /// <summary>
        /// Maps a DBSpecificationAttributeCollection to a SpecificationAttributeCollection
        /// </summary>
        /// <param name="dbCollection">DBSpecificationAttributeCollection</param>
        /// <returns>SpecificationAttributeCollection</returns>
        private static SpecificationAttributeCollection DBMapping(DBSpecificationAttributeCollection dbCollection)
        {
            if (dbCollection == null)
            {
                return(null);
            }

            SpecificationAttributeCollection collection = new SpecificationAttributeCollection();

            foreach (DBSpecificationAttribute dbItem in dbCollection)
            {
                SpecificationAttribute item = DBMapping(dbItem);
                collection.Add(item);
            }

            return(collection);
        }
        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);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Inserts a specification attribute
        /// </summary>
        /// <param name="specificationAttribute">The specification attribute</param>
        public void InsertSpecificationAttribute(SpecificationAttribute specificationAttribute)
        {
            if (specificationAttribute == null)
            {
                throw new ArgumentNullException("specificationAttribute");
            }

            specificationAttribute.Name = CommonHelper.EnsureNotNull(specificationAttribute.Name);
            specificationAttribute.Name = CommonHelper.EnsureMaximumLength(specificationAttribute.Name, 100);



            _context.SpecificationAttributes.AddObject(specificationAttribute);
            _context.SaveChanges();

            if (this.CacheEnabled)
            {
                _cacheManager.RemoveByPattern(SPECIFICATIONATTRIBUTE_PATTERN_KEY);
                _cacheManager.RemoveByPattern(SPECIFICATIONATTRIBUTEOPTION_PATTERN_KEY);
                _cacheManager.RemoveByPattern(PRODUCTSPECIFICATIONATTRIBUTE_PATTERN_KEY);
            }
        }
        public SpecificationAttribute SaveInfo()
        {
            SpecificationAttribute specificationAttribute = this.SpecificationAttributeService.GetSpecificationAttributeById(this.SpecificationAttributeId);

            if (specificationAttribute != null)
            {
                specificationAttribute.Name = txtName.Text;
                specificationAttribute.DisplayOrder =  txtDisplayOrder.Value;
                this.SpecificationAttributeService.UpdateSpecificationAttribute(specificationAttribute);
            }
            else
            {
                specificationAttribute = new SpecificationAttribute()
                {
                    Name = txtName.Text,
                    DisplayOrder = txtDisplayOrder.Value
                };
                this.SpecificationAttributeService.InsertSpecificationAttribute(specificationAttribute);
            }

            SaveLocalizableContent(specificationAttribute);

            return specificationAttribute;
        }