Esempio n. 1
0
        /// <summary>
        /// Updates the extendable object with values from the custom attribute collection.
        /// </summary>
        /// <param name="extendableToUpdate">The extendable to update.</param>
        /// <param name="customAttributeDetails">The custom attribute details.</param>
        /// <returns>The updated Extendable object</returns>
        /// <exception cref="CustomAttributeException">Unknown AttributeType for AttributeKey: {0}</exception>
        public IExtendable UpdateExtendable(IExtendable extendableToUpdate, IEnumerable <CustomAttributeDetail> customAttributeDetails, string updatedByUser)
        {
            if (customAttributeDetails == null || !customAttributeDetails.Any())
            {
                return(extendableToUpdate);
            }

            foreach (var customAttribute in customAttributeDetails)
            {
                switch (customAttribute.Type)
                {
                case CustomAttributeType.Numeric:
                    extendableToUpdate.SetAttributeValue(customAttribute.AttributeKey, (decimal)ExtractValue(customAttribute), updatedByUser);
                    break;

                case CustomAttributeType.String:
                    extendableToUpdate.SetAttributeValue(customAttribute.AttributeKey, ExtractValue(customAttribute).ToString(), updatedByUser);
                    break;

                case CustomAttributeType.Selection:
                    extendableToUpdate.SetAttributeValue(customAttribute.AttributeKey, (Int32)ExtractValue(customAttribute), updatedByUser);
                    break;

                case CustomAttributeType.DateTime:
                    extendableToUpdate.SetAttributeValue(customAttribute.AttributeKey, Convert.ToDateTime(ExtractValue(customAttribute)), updatedByUser);
                    break;

                default:
                    throw new CustomAttributeException("Unknown AttributeType for AttributeKey: {0}", customAttribute.AttributeKey);
                }
            }

            return(extendableToUpdate);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the extendable object with values from the custom attribute collection.
        /// </summary>
        /// <param name="extendableToUpdate">The extendable to update.</param>
        /// <param name="customAttributeDetails">The custom attribute details.</param>
        /// <returns>The updated Extendable object</returns>
        /// <exception cref="CustomAttributeException">Unknown AttributeType for AttributeKey: {0}</exception>
        public IExtendable UpdateExtendable(IExtendable extendableToUpdate, IEnumerable <CustomAttributeDetail> customAttributeDetails, string updatedByUser)
        {
            if (customAttributeDetails == null || !customAttributeDetails.Any())
            {
                return(extendableToUpdate);
            }

            foreach (var customAttribute in customAttributeDetails)
            {
                try
                {
                    switch (customAttribute.Type)
                    {
                    case CustomAttributeType.Numeric:
                        extendableToUpdate.SetAttributeValue <Decimal>(customAttribute.AttributeKey, customAttribute.Value == null ? 0 : Convert.ToDecimal(customAttribute.Value), updatedByUser);
                        break;

                    case CustomAttributeType.String:
                        extendableToUpdate.SetAttributeValue <String>(customAttribute.AttributeKey, customAttribute.Value == null ? string.Empty : customAttribute.Value.ToString(), updatedByUser);
                        break;

                    case CustomAttributeType.Selection:
                        extendableToUpdate.SetAttributeValue <Int32>(customAttribute.AttributeKey, customAttribute.Value == null ? 0 : Convert.ToInt32(customAttribute.Value), updatedByUser);
                        break;

                    case CustomAttributeType.DateTime:
                        extendableToUpdate.SetAttributeValue <DateTime>(customAttribute.AttributeKey, customAttribute.Value == null || String.IsNullOrEmpty(customAttribute.Value.ToString()) ? DateTime.MinValue : Convert.ToDateTime(customAttribute.Value), updatedByUser);
                        break;

                    default:
                        throw new CustomAttributeException("Unknown AttributeType for AttributeKey: {0}", customAttribute.AttributeKey);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception($"Error setting attribute value for {customAttribute.AttributeKey} with error {ex.Message}");
                }
            }

            return(extendableToUpdate);
        }