Ejemplo n.º 1
0
        /// <summary>
        /// Returns list of Custom Attributes for the specified extendable object with values prepopulated
        /// </summary>
        /// <param name="extendableObject">The extendable object.</param>
        /// <returns></returns>
        public List <CustomAttributeDetail> BuildModelExtension(IExtendable extendableObject)
        {
            var modelExtension = new List <CustomAttributeDetail>();

            var attributeConfigs = attributeConfigRepository.RetrieveAttributeConfigurationsForType(extendableObject.GetType().Name);

            if (attributeConfigs == null || !attributeConfigs.Any())
            {
                attributeConfigs = attributeConfigRepository.RetrieveAttributeConfigurationsForType(extendableObject.GetType().BaseType.Name);
            }

            if (attributeConfigs == null || !attributeConfigs.Any())
            {
                return(modelExtension);
            }

            foreach (var customAttributeConfig in attributeConfigs)
            {
                var attributeDetail = new CustomAttributeDetail()
                {
                    Id              = customAttributeConfig.Id,
                    Type            = customAttributeConfig.CustomAttributeType,
                    Category        = customAttributeConfig.Category,
                    AttributeKey    = customAttributeConfig.AttributeKey,
                    IsRequired      = customAttributeConfig.IsRequired,
                    StringMaxLength = customAttributeConfig.StringMaxLength,
                    NumericMinValue = customAttributeConfig.NumericMinValue,
                    NumericMaxValue = customAttributeConfig.NumericMaxValue,
                    FutureDateOnly  = customAttributeConfig.FutureDateOnly,
                    PastDateOnly    = customAttributeConfig.PastDateOnly,
                    IsSearchable    = customAttributeConfig.IsSearchable,
                    Value           = GetAttributeValue(extendableObject, customAttributeConfig)
                };

                //if (customAttributeConfig.CustomAttributeType == CustomAttributeType.Selection)
                //{
                //    var refData = RetrieveSelectionDataForAttribute(customAttributeConfig.AttributeKey);

                //    if (refData != null && refData.Any())
                //        attributeDetail.RefData = refData.Select(s =>
                //                new SelectListItem
                //                {
                //                    Value = s.SelectionKey.ToString(),
                //                    Text = s.Value,
                //                    Selected = (attributeDetail.Value != null && s.Id == Convert.ToInt32(attributeDetail.Value))
                //                }).ToList();
                //}

                modelExtension.Add(attributeDetail);
            }

            return(modelExtension);
        }
Ejemplo n.º 2
0
 public void ValidateAndSetAttributeValue <T>(CustomAttributeDetail attributeDetail, T attributeValue, string updatedByUser)
 {
     customAttributes.ValidateAndSetAttributeValue(attributeDetail, attributeValue, updatedByUser);
 }