Example #1
0
        public static BrandMetadataSetting RenameMetadataFieldName(int brandMetadataSettingId, string fieldName)
        {
            fieldName = fieldName.Trim();

            if (StringUtils.IsBlank(fieldName))
            {
                throw new SystemException("Field name cannot be empty");
            }

            BrandMetadataSetting setting = BrandMetadataSetting.Get(brandMetadataSettingId);

            if (setting.IsNull)
            {
                throw new SystemException("Metadata setting not found");
            }

            BrandMetadataSettingFinder finder = new BrandMetadataSettingFinder {
                BrandId = setting.BrandId, FieldName = fieldName
            };
            int count = BrandMetadataSetting.GetCount(finder);

            if (count > 0)
            {
                throw new SystemException(string.Format("Another metadata setting with the name '{0}' already exists in this brand", fieldName));
            }

            setting.FieldName = fieldName;
            BrandMetadataSetting.Update(setting);

            CacheManager.InvalidateCache("Brand", CacheType.All);

            return(setting);
        }
        /// <summary>
        /// returns all custom metadata settings for a supplied brand
        /// </summary>
        /// <param name="brandId"></param>
        /// <returns></returns>
        public static EntityList <BrandMetadataSetting> GetCustomMetadataSettings(int brandId)
        {
            var finder = new BrandMetadataSettingFinder {
                BrandId = brandId, IsCustom = true
            };
            var settings = BrandMetadataSetting.FindMany(finder);

            return(settings);
        }
Example #3
0
        private static List <BrandMetadataSetting> GetMetadataSettings(int brandId)
        {
            // Get all of the metadata settings for this brand
            BrandMetadataSettingFinder finder = new BrandMetadataSettingFinder {
                BrandId = brandId
            };
            List <BrandMetadataSetting> settings = BrandMetadataSetting.FindMany(finder);

            // Return settings if found
            if (settings.Count == 0)
            {
                // Otherwise, we need to get the default settings
                List <int> brandIdList = new List <int>();

                // Check the master brand first
                if (brandId != WebsiteBrandManager.GetMasterBrand().BrandId)
                {
                    brandIdList.Add(WebsiteBrandManager.GetMasterBrand().BrandId.GetValueOrDefault());
                }

                // Then all subsequent brands
                foreach (Brand brand in BrandCache.Instance.GetList())
                {
                    if (!brandIdList.Contains(brand.BrandId.GetValueOrDefault()))
                    {
                        brandIdList.Add(brand.BrandId.GetValueOrDefault());
                    }
                }

                // Now check each brand
                foreach (int id in brandIdList)
                {
                    // Get the metadata settings in this brand
                    finder = new BrandMetadataSettingFinder {
                        BrandId = id, IsCustom = false
                    };
                    settings = BrandMetadataSetting.FindMany(finder);

                    if (settings.Count > 0)
                    {
                        // Settings found.  Copy all of them to the brand
                        // being edited and drop out of the loop as we've
                        // found what we're looking for.

                        foreach (BrandMetadataSetting setting in settings)
                        {
                            setting.BrandMetadataSettingId = null;
                            setting.BrandId = brandId;
                            BrandMetadataSetting.Update(setting);
                        }

                        break;
                    }
                }
            }

            // Still no settings, so copy them from the default metadata options
//			if (settings.Count == 0)
//			{
            // Still no settings so try and add these using our configuration settings
//				foreach (MetadataOption option in m_MetadataOptions)
//					AddMetadataSettingToDatabase(brandId, option, settings);
//			}
//
            // There should be the same number of settings in the database as there are default metadata
            // options or this means that these are out of sync. In this case, add the new setting to the list.
//
//			if (settings.Count < m_MetadataOptions.Count)
//			{
            // First get the missing settings.  These are items that exist in the metadata options list
            // but not in the list we got from the database.
//				var missingSettings = (from o in m_MetadataOptions
//				                       where !settings.Any(s => s.FieldId == o.FieldId)
//				                       select o);
//
            // Now add them to the database and the settings list
//				foreach (var setting in missingSettings)
//					AddMetadataSettingToDatabase(brandId, setting, settings);
//			}

            return(settings);
        }