Exemplo n.º 1
0
        public string GetCustomAttributeValue(CustomAttributeConfiguration config, IExtendable extended)
        {
            DateTime dttemp;

            if (extended.GetAttributeValue(config.AttributeKey) == null)
            {
                return("");
            }
            ;

            var val = extended.GetAttributeValue(config.AttributeKey).ToString();

            switch (config.CustomAttributeType)
            {
            case CustomAttributeType.FirstClassProperty:
            case CustomAttributeType.None:
                return(string.Empty);

            case CustomAttributeType.Numeric:
            case CustomAttributeType.String:
                return(val);

            case CustomAttributeType.Selection:
                var selection = _unitOfWork.Repository <SelectionDataItem>().Queryable().SingleOrDefault(s => s.AttributeKey == config.AttributeKey && s.SelectionKey == val);
                return(selection.Value);

            case CustomAttributeType.DateTime:
                return(DateTime.TryParse(val, out dttemp) ? Convert.ToDateTime(val).ToString("yyyy-MM-dd") : val);

            default:
                return(string.Empty);
            }
        }
Exemplo n.º 2
0
        private object GetAttributeValue(IExtendable extendable, CustomAttributeConfiguration config)
        {
            switch (config.CustomAttributeType)
            {
            case CustomAttributeType.Numeric:
                return((extendable == null || extendable.GetAttributeValue(config.AttributeKey) == null)
                        ? default(decimal)
                        : extendable.GetAttributeValue(config.AttributeKey));

            case CustomAttributeType.String:
                return((extendable == null || extendable.GetAttributeValue(config.AttributeKey) == null)
                        ? " "// Not a big fan of this but Razor does not recognise empty strings and ends up not rendering a control for the attribute.
                        : extendable.GetAttributeValue(config.AttributeKey));

            case CustomAttributeType.Selection:
                return((extendable == null || extendable.GetAttributeValue(config.AttributeKey) == null)
                        ? default(int)
                        : extendable.GetAttributeValue(config.AttributeKey));

            case CustomAttributeType.DateTime:
                return((extendable == null || extendable.GetAttributeValue(config.AttributeKey) == null)
                        ? default(DateTime)
                        : extendable.GetAttributeValue(config.AttributeKey));

            default:
                throw new CustomAttributeException("Unknown AttributeType for AttributeKey: {0}", config.AttributeKey);
            }
        }
Exemplo n.º 3
0
        public void AddCustomAttribute(CustomAttributeConfigDetail customAttribute)
        {
            var newCustomAttribute = new CustomAttributeConfiguration()
            {
                ExtendableTypeName  = customAttribute.EntityName,
                Category            = customAttribute.Category,
                AttributeKey        = customAttribute.AttributeName,
                AttributeDetail     = customAttribute.AttributeDetail,
                CustomAttributeType = customAttribute.CustomAttributeType,
                IsRequired          = customAttribute.Required,
                IsSearchable        = customAttribute.Searchable
            };

            switch (newCustomAttribute.CustomAttributeType)
            {
            case CustomAttributeType.Numeric:
                if (customAttribute.NumericMinValue.HasValue)
                {
                    newCustomAttribute.NumericMinValue = customAttribute.NumericMinValue.Value;
                }

                if (customAttribute.NumericMaxValue.HasValue)
                {
                    newCustomAttribute.NumericMaxValue = customAttribute.NumericMaxValue.Value;
                }
                break;

            case CustomAttributeType.String:
                if (customAttribute.StringMaxLength.HasValue)
                {
                    newCustomAttribute.StringMaxLength = customAttribute.StringMaxLength.Value;
                }
                break;

            case CustomAttributeType.DateTime:
                newCustomAttribute.FutureDateOnly = customAttribute.FutureDateOnly;
                newCustomAttribute.PastDateOnly   = customAttribute.PastDateOnly;
                break;

            default:
                break;
            }

            customAttributeConfigRepository.Save(newCustomAttribute);

            if (newCustomAttribute.CustomAttributeType == CustomAttributeType.Selection)
            {
                var newSelectionDataItem = new SelectionDataItem()
                {
                    AttributeKey = customAttribute.AttributeName,
                    Value        = "",
                    SelectionKey = "0"
                };

                selectionDataRepository.Save(newSelectionDataItem);
            }
        }