示例#1
0
        public static BaseMetadata CreateInstance(MetadataField field, BaseMetadata metadata, Guid?referenceCode = null)
        {
            BaseMetadata result = null;

            if (referenceCode.IsNull())
            {
                referenceCode = Guid.Empty;
            }

            switch (field.Type)
            {
            case FieldType.Store:
                result = new StoreMetadata()
                {
                    StoreCode = referenceCode.Value
                };
                break;

            case FieldType.Account:
                result = new AccountMetadata()
                {
                    AccountCode = referenceCode.Value
                };
                break;
            }

            result.Field = field;

            if (!metadata.IsNull())
            {
                result.Value = metadata.Value;
            }

            return(result);
        }
示例#2
0
 public BaseMetadata(DTO.MetadataField field)
     : this()
 {
     Field = new MetadataField {
         JsonId = field.JsonId
     };
     Value = field.Value.AsString();
 }
示例#3
0
 public MetadataField(DO.MetadataField field)
 {
     this.Code      = field.Code;
     this.JsonId    = field.JsonId;
     this.Name      = field.Name;
     this.Type      = field.Type.AsInt();
     this.Format    = field.Format.AsInt();
     this.Validator = !field.Validator.IsNull() ? field.Validator.GetResult() : null;
     this.SaveDate  = field.SaveDate;
 }
示例#4
0
        public MetadataField(DO.MetadataField field, BaseMetadata metadata)
            : this(field)
        {
            switch (field.Format)
            {
            case FormatType.Integer:

                if (metadata.Value.IsNullOrWhiteSpace())
                {
                    Value = null;
                }
                else
                {
                    Value = metadata.Value.AsLong();
                }

                break;

            case FormatType.Decimal:

                if (metadata.Value.IsNullOrWhiteSpace())
                {
                    Value = null;
                }
                else
                {
                    decimal _value;

                    decimal.TryParse(metadata.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out _value);

                    Value = _value;
                }

                break;

            case FormatType.Date:
                var value = metadata.Value.AsDateTime();

                if (metadata.Value.IsNullOrWhiteSpace() || value == DateTime.MinValue)
                {
                    Value = null;
                }
                else
                {
                    Value = value;
                }

                break;

            case FormatType.Boolean:

                if (metadata.Value.IsNullOrWhiteSpace())
                {
                    Value = null;
                }
                else
                {
                    Value = metadata.Value.AsBool();
                }

                break;

            default:
                Value = metadata.Value;
                break;
            }
        }