Beispiel #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);
        }
Beispiel #2
0
        /// <summary>
        /// Returns list of Custom Attributes for the specified extendable object with the 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();
                attributeDetail.AttributeKey = customAttributeConfig.AttributeKey;
                attributeDetail.Category     = customAttributeConfig.Category;
                attributeDetail.Type         = customAttributeConfig.CustomAttributeType;
                attributeDetail.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);
        }
        public void BuildEditModel_RetrievesAttribueConfigsForSpecifiedType()
        {
            // Act
            handlerUnderTest.BuildModelExtension(extendedObject);

            // Assert
            attributeConfigRepository.Verify(c => c.RetrieveAttributeConfigurationsForType(extendedObject.GetType().Name), Times.Exactly(1));
        }