Example #1
0
        /// <summary>
        /// Evaluate a given property and decide whether it's an update
        /// </summary>
        /// <param name="currentSettings"></param>
        /// <param name="prop"></param>
        /// <param name="target"></param>
        /// <param name="websiteId"></param>
        /// <returns></returns>
        public static PendingChange EvaluateProperty(EntityCollection currentSettings, PropertyInfo prop, object target, Guid websiteId)
        {
            string        newValString = null;
            PendingChange entUpdate    = null;

            var attrib = prop
                         .GetCustomAttributes(true)
                         .Where(a => a is SiteSettingsAttribute)
                         .FirstOrDefault() as SiteSettingsAttribute;

            if (attrib != null)
            {
                var newVal     = prop.GetValue(target);
                var descAttrib = prop
                                 .GetCustomAttributes(true)
                                 .Where(a => a is DescriptionAttribute)
                                 .FirstOrDefault() as DescriptionAttribute;

                var ignoreCase = newVal is bool;
                newValString = GetPropertyString(prop, newVal, attrib);

                entUpdate = CheckAttributeValue(currentSettings, attrib.NameFormat, newValString, websiteId, ignoreCase, attrib.IsRequired, descAttrib?.Description);

                if (entUpdate != null)
                {
                    // now that we have a change - new or update - validated it
                    var messages = ValidatorHelper.ValidateProperty(prop, target);
                    entUpdate.ValidationMessage = string.Join(",", messages.ToArray());
                }
            }
            return(entUpdate);
        }
Example #2
0
        /// <summary>
        /// Evaluate a list of Properties for changes
        /// </summary>
        /// <param name="currentSettings"></param>
        /// <param name="props"></param>
        /// <param name="target"></param>
        /// <param name="slug"></param>
        /// <param name="slugValue"></param>
        /// <param name="changesList"></param>
        public static void EvaluatePropertyList(EntityCollection currentSettings, PropertyInfo[] props, object target, string slug, string slugValue, Guid websiteId, ref List <PendingChange> changesList)
        {
            foreach (var prop in props)
            {
                // special case here since we need to update the name
                var siteSettingsAttrib = prop
                                         .GetCustomAttributes(true)
                                         .Where(a => a is SiteSettingsAttribute)
                                         .FirstOrDefault() as SiteSettingsAttribute;

                if (siteSettingsAttrib != null)
                {
                    var newVal = prop.GetValue(target);

                    var descAttrib = prop
                                     .GetCustomAttributes(true)
                                     .Where(a => a is DescriptionAttribute)
                                     .FirstOrDefault() as DescriptionAttribute;

                    var ignoreCase   = newVal is bool;
                    var newValString = GetPropertyString(prop, newVal, siteSettingsAttrib);
                    var name         = siteSettingsAttrib.NameFormat.Replace(slug, slugValue);
                    var entUpdate    = CheckAttributeValue(currentSettings, name, newValString, websiteId, ignoreCase, siteSettingsAttrib.IsRequired, descAttrib?.Description);

                    if (entUpdate != null)
                    {
                        // now that we have a change - new or update - validated it
                        var messages = ValidatorHelper.ValidateProperty(prop, target);
                        entUpdate.ValidationMessage = string.Join(",", messages.ToArray());
                        changesList.Add(entUpdate);
                    }
                }
            }
        }