コード例 #1
0
        public string GetUpdatedByUser(string attributeKey)
        {
            var selectionAttribute = CustomSelectionAttributes.SingleOrDefault(s => s.Key == attributeKey);

            if (selectionAttribute != null)
            {
                return(selectionAttribute.UpdatedByUser);
            }

            var stringAttribute = CustomStringAttributes.SingleOrDefault(s => s.Key == attributeKey);

            if (stringAttribute != null)
            {
                return(stringAttribute.UpdatedByUser);
            }

            var dateTimeAttribute = CustomDateTimeAttributes.SingleOrDefault(s => s.Key == attributeKey);

            if (dateTimeAttribute != null)
            {
                return(dateTimeAttribute.UpdatedByUser);
            }

            var numericAttribute = CustomNumericAttributes.SingleOrDefault(s => s.Key == attributeKey);

            if (numericAttribute != null)
            {
                return(numericAttribute.UpdatedByUser);
            }

            return(string.Empty);
        }
コード例 #2
0
        public object GetAttributeValue(string attributeKey)
        {
            var selectionAttribute = CustomSelectionAttributes.SingleOrDefault(s => s.Key == attributeKey);

            if (selectionAttribute != null)
            {
                return(selectionAttribute.Value);
            }

            var stringAttribute = CustomStringAttributes.SingleOrDefault(s => s.Key == attributeKey);

            if (stringAttribute != null)
            {
                return(stringAttribute.Value);
            }

            var dateTimeAttribute = CustomDateTimeAttributes.SingleOrDefault(s => s.Key == attributeKey);

            if (dateTimeAttribute != null)
            {
                return(dateTimeAttribute.Value);
            }

            var numericAttribute = CustomNumericAttributes.SingleOrDefault(s => s.Key == attributeKey);

            if (numericAttribute != null)
            {
                return(numericAttribute.Value);
            }

            return(null);
        }
コード例 #3
0
        public DateTime GetUpdatedDate(string attributeKey)
        {
            var selectionAttribute = CustomSelectionAttributes.SingleOrDefault(s => s.Key == attributeKey);

            if (selectionAttribute != null)
            {
                return(selectionAttribute.UpdatedDate);
            }

            var stringAttribute = CustomStringAttributes.SingleOrDefault(s => s.Key == attributeKey);

            if (stringAttribute != null)
            {
                return(stringAttribute.UpdatedDate);
            }

            var dateTimeAttribute = CustomDateTimeAttributes.SingleOrDefault(s => s.Key == attributeKey);

            if (dateTimeAttribute != null)
            {
                return(dateTimeAttribute.UpdatedDate);
            }

            var numericAttribute = CustomNumericAttributes.SingleOrDefault(s => s.Key == attributeKey);

            if (numericAttribute != null)
            {
                return(numericAttribute.UpdatedDate);
            }

            return(default(DateTime));
        }
コード例 #4
0
        private CustomAttributeType GetCurrentAttributeTypeIfExists(string attributeKey)
        {
            if (CustomDateTimeAttributes.Any(c => c.Key == attributeKey))
            {
                return(CustomAttributeType.DateTime);
            }
            if (CustomStringAttributes.Any(c => c.Key == attributeKey))
            {
                return(CustomAttributeType.String);
            }
            if (CustomSelectionAttributes.Any(c => c.Key == attributeKey))
            {
                return(CustomAttributeType.Selection);
            }
            if (CustomNumericAttributes.Any(c => c.Key == attributeKey))
            {
                return(CustomAttributeType.Numeric);
            }

            return(CustomAttributeType.None);
        }
コード例 #5
0
        public void SetAttributeValue <T>(string attributeKey, T attributeValue, string updatedByUser)
        {
            if (!allowedTypes.Contains(typeof(T)))
            {
                throw new CustomAttributeException("Custom attribute of Type {0} is not supported.", typeof(T).Name);
            }

            var existingType = GetCurrentAttributeTypeIfExists(attributeKey);

            switch (typeof(T).Name)
            {
            case "Int32":
                var intValue = Convert.ToInt32(attributeValue);

                var attribute = CustomSelectionAttributes.SingleOrDefault(a => a.Key == attributeKey);

                if (attribute != null)
                {
                    attribute.SetAttributeValue(intValue, updatedByUser);
                }
                else
                {
                    if (existingType != CustomAttributeType.None)
                    {
                        throw new CustomAttributeException("Custom Attribute value for {0} is of an incorrect type. Please cast the value before setting.", attributeKey);
                    }

                    CustomSelectionAttributes.Add(new CustomSelectionAttribute {
                        Key = attributeKey, Value = intValue, UpdatedByUser = updatedByUser
                    });
                }
                break;

            case "String":
                var stringValue = attributeValue.ToString();

                var stringAttribute = CustomStringAttributes.SingleOrDefault(a => a.Key == attributeKey);

                if (stringAttribute != null)
                {
                    stringAttribute.SetAttributeValue(stringValue, updatedByUser);
                }
                else
                {
                    if (existingType != CustomAttributeType.None)
                    {
                        throw new CustomAttributeException("Custom Attribute value for {0} is of an incorrect type. Please cast the value before setting.", attributeKey);
                    }

                    CustomStringAttributes.Add(new CustomStringAttribute {
                        Key = attributeKey, Value = stringValue, UpdatedByUser = updatedByUser
                    });
                }
                break;

            case "DateTime":
                var dateTimeValue = Convert.ToDateTime(attributeValue);

                var dateTimeAttribute = CustomDateTimeAttributes.SingleOrDefault(a => a.Key == attributeKey);

                if (dateTimeAttribute != null)
                {
                    dateTimeAttribute.SetAttributeValue(dateTimeValue, updatedByUser);
                }
                else
                {
                    if (existingType != CustomAttributeType.None)
                    {
                        throw new CustomAttributeException("Custom Attribute value for {0} is of an incorrect type. Please cast the value before setting.", attributeKey);
                    }

                    CustomDateTimeAttributes.Add(new CustomDateTimeAttribute {
                        Key = attributeKey, Value = dateTimeValue, UpdatedByUser = updatedByUser
                    });
                }
                break;

            case "Decimal":
                var decimalValue = Convert.ToDecimal(attributeValue);

                var decimalAttribute = CustomNumericAttributes.SingleOrDefault(a => a.Key == attributeKey);

                if (decimalAttribute != null)
                {
                    decimalAttribute.SetAttributeValue(decimalValue, updatedByUser);
                }
                else
                {
                    if (existingType != CustomAttributeType.None)
                    {
                        throw new CustomAttributeException("Custom Attribute value for {0} is of an incorrect type. Please cast the value before setting.", attributeKey);
                    }
                    CustomNumericAttributes.Add(new CustomNumericAttribute {
                        Key = attributeKey, Value = decimalValue, UpdatedByUser = updatedByUser
                    });
                }
                break;

            default:
                // This should never happen
                throw new CustomAttributeException("Unable to set custom attribute; Key: {0}, Value: {1}, Type: {2}", attributeKey, attributeValue, typeof(T).Name);
            }
        }