Ejemplo n.º 1
0
        public static object SetExt(this Base_Article article, Base_CatalogExt catExt, object value)
        {
            if (catExt == null)
            {
                return(null);
            }
            var artExt = article.Exts.FirstOrDefault(ext => ext.CatlogExtId == catExt.Id);

            if (artExt == null)
            {
                artExt = new Base_ArticleExt
                {
                    CatlogExtId = catExt.Id,
                };
                article.Exts.Add(artExt);
            }
            ;

            string strValue = null;

            switch ((ExtDataType)catExt.DataType)
            {
            case ExtDataType.Currency:
                Decimal?dec = CommOp.ToDecimalNull(value);
                if (dec != null)
                {
                    strValue = dec.Value.ToString();
                }
                break;

            case ExtDataType.FloatNumber:
                double?flt = CommOp.ToDoubleNull(value);
                if (flt != null)
                {
                    strValue = flt.Value.ToString();
                }
                break;

            case ExtDataType.DateAndTime:
            case ExtDataType.Date:
                DateTime?dt = CommOp.ToDateTimeNull(value);
                if (dt != null)
                {
                    strValue = dt.Value.ToString("yyyy-MM-dd HH:mm:ss");
                }
                break;

            case ExtDataType.SingleNumber:
                long?lng = CommOp.ToLongNull(value);
                if (lng != null)
                {
                    strValue = lng.Value.ToString();
                }
                break;

            case ExtDataType.Bool:
                value    = CommOp.ToBool(value);
                strValue = value.ToString();
                break;

            default:
                strValue = CommOp.ToStr(value);
                if (strValue.IsEmpty())
                {
                    strValue = null;
                }
                break;
            }
            artExt.Value = strValue;
            return(value);
        }