Exemple #1
0
 public Json2SquidexConverter(string?fields = null)
 {
     if (fields != null)
     {
         mapping = JsonMapping.ForCsv2Json(fields);
     }
 }
Exemple #2
0
        public void TestTranslationOfExistingDestinationObjectWithIdInMapping()
        {
            ModelType      outType;
            IList <string> propertyNames = new List <string>();

            propertyNames.Add("Employee Id");
            propertyNames.Add("Location");
            propertyNames.Add("FirstName");
            propertyNames.Add("LastName");
            dynamicProvider.CreateType(propertyNames, out outType, "TypeName");

            //load a new instance
            IList <string> instanceValues = new List <string>();

            instanceValues.Add("1");
            instanceValues.Add("23");
            instanceValues.Add("John");
            instanceValues.Add("Doe");
            dynamicProvider.CreateInstance(outType, instanceValues);

            string mapping = @"[{PropertyPath : 'firstName',Expression : 'FirstName'}, {PropertyPath : 'Id',Expression : 'Employee Id'}]";

            JsonMapping map = new JsonMapping(mapping);

            //The test will overwrite the existing account object with new values from the source entity.
            IEnumerable <ModelInstance> translatedInstances = translator.Translate(ModelContext.Current.GetModelType("Account"), outType, dynamicProvider.GetModelInstances(ModelContext.Current.GetModelType("TypeName")), map, (type, instance, id) =>
            {
                return(type.Create(id));
            });

            Assert.AreEqual(translatedInstances.ElementAt(0)["firstName"], "John");
            Assert.AreEqual(translatedInstances.ElementAt(0)["lastName"], "User");
            Assert.AreEqual(translatedInstances.ElementAt(0)["accountNumber"], "1234");
        }
Exemple #3
0
        public IList <TEntity> GetListNoTracking(Expression <Func <TEntity, bool> > predicate = null)
        {
            var result = Store.FindByIdsNoTracking(predicate).ToList();

            // 扩展属性处理
            result.Foreach(r => { r = JsonMapping.ConvertToExtension(r); });
            return(result);
        }
Exemple #4
0
        public IList <TEntity> GetList()
        {
            var result = Store.GetList().ToList();

            // 扩展属性处理
            result.Foreach(r => { r = JsonMapping.ConvertToExtension(r); });
            return(result);
        }
Exemple #5
0
        /// <summary>
        ///     Sets the value.
        ///     根据前端页面表单HttpContext设置内容
        /// </summary>
        /// <param name="httpContext">The HTTP context.</param>
        public ServiceResult SetValue(HttpContext httpContext)
        {
            var activityModule = AutoMapping.SetValue <GroupBuyActivity>(httpContext); // 活动模块

            activityModule = JsonMapping.HttpContextToExtension <GroupBuyActivity>(activityModule, httpContext);
            var priceSytles =
                Resolve <IAutoConfigService>()
                .GetList <PriceStyleConfig>(r => r.Status == Status.Normal); // 状态不正常的商品,可能不支持价格类型
            var moneyTypes = Resolve <IAutoConfigService>().MoneyTypes();    // 所有货币类型
            var productId  = httpContext.Request.Form["ProductId"].ConvertToLong();
            var product    = Resolve <IProductService>().GetSingle(r => r.Id == productId);

            if (product == null)
            {
                return(ServiceResult.Failure("商品不存在"));
            }

            var priceStyleConfig = Resolve <IAutoConfigService>().GetList <PriceStyleConfig>()
                                   .FirstOrDefault(r => r.Id == product.PriceStyleId);

            if (product.MinCashRate == 0)
            {
                product.MinCashRate = priceStyleConfig.MinCashRate;
            }

            activityModule.SkuProducts.Foreach(r =>
            {
                r.GroupBuyDisplayPrice = Resolve <IProductGoodsService>().Resolve <IProductService>()
                                         .GetDisplayPrice(r.Price, priceStyleConfig.Id, priceStyleConfig.MinCashRate);
                // 如果商品中有价格参数,则使员商品中的最小抵现价格
                if (priceStyleConfig != null)
                {
                    var moneyConfig = moneyTypes.FirstOrDefault(e => e.Id == priceStyleConfig.MoneyTypeId);
                    if (moneyConfig?.RateFee == 0)
                    {
                        moneyConfig.RateFee = 1;
                    }
                    // 如果不是现金商品
                    if (priceStyleConfig.PriceStyle != PriceStyle.CashProduct)
                    {
                        r.MinPayCash  = Math.Round(r.Price * priceStyleConfig.MinCashRate, 2); // 最低可使用的现金资产
                        r.MaxPayPrice = Math.Round(r.Price * (1 - priceStyleConfig.MinCashRate) / moneyConfig.RateFee,
                                                   2);                                         // 最高可使用的现金资产
                    }
                    else
                    {
                        r.MaxPayPrice = 0;       // 现金商品,最高可使用的虚拟资产为0
                        r.MinPayCash  = r.Price; //现金商品,最低使用的现金为价格
                    }
                }
            });

            var result = ServiceResult.Success;

            result.ReturnObject = activityModule;
            return(result);
        }
Exemple #6
0
        public TEntity GetSingle(Expression <Func <TEntity, bool> > predicate)
        {
            var find = Store.GetSingle(predicate);

            if (find != null)
            {
                find = JsonMapping.ConvertToExtension(find);
            }

            return(find);
        }
        public void TestCreation()
        {
            string mapping = @"[{PropertyPath : 'Number',Expression : '[Location #]'}, {PropertyPath : 'ServiceAddress.Line1',Expression : '[Full Service Address]'}, {PropertyPath : 'ServiceAddress.City',Expression : '[Service City]'}]";

            JsonMapping          map  = new JsonMapping(mapping);
            ExpressionToProperty test = new ExpressionToProperty();

            test.Expression   = "[Service City]";
            test.PropertyPath = "ServiceAddress.City";

            Assert.AreEqual(3, map.GetMapping().Count());
            Assert.AreEqual(true, test.Equals(map.GetMapping().ElementAt(2)));
        }
Exemple #8
0
        public PagedList <TEntity> GetPagedList(IPageQuery <TEntity> queryCriteria)
        {
            var query = UnitOfWork.Set <TEntity>();

            if (queryCriteria == null)
            {
                return(PagedList <TEntity> .Create(query.ToList(), query.Count(), query.Count(), 1));
            }

            var count       = queryCriteria.ExecuteCountQuery(query);
            var queryResult = queryCriteria.Execute(query);
            var resultList  = queryResult.ToList();

            resultList.ForEach(r => { r = JsonMapping.ConvertToExtension(r); });
            return(PagedList <TEntity> .Create(resultList, count, queryCriteria.PageSize, queryCriteria.PageIndex));
        }
Exemple #9
0
        public void TestComplexExressions()
        {
            ModelType      outType;
            IList <string> propertyNames = new List <string>();

            propertyNames.Add("Employee Id");
            propertyNames.Add("Location");
            propertyNames.Add("FirstName");
            propertyNames.Add("LastName");
            dynamicProvider.CreateType(propertyNames, out outType, "TypeName");

            //load a new instance
            IList <string> instanceValues = new List <string>();

            instanceValues.Add("1");
            instanceValues.Add("23");
            instanceValues.Add("John");
            instanceValues.Add("Doe");
            dynamicProvider.CreateInstance(outType, instanceValues);

            instanceValues = new List <string>();
            instanceValues.Add("2");
            instanceValues.Add("23");
            instanceValues.Add("Jane");
            instanceValues.Add("Doe");
            dynamicProvider.CreateInstance(outType, instanceValues);

            string mapping = "[{PropertyPath : 'firstName',Expression : 'FirstName == \"John\" ? \"MyNameIsJohn\" : \"MyNameIsJohn\"'}, {PropertyPath : 'lastName',Expression : 'LastName.Length'}, {PropertyPath : 'accountNumber',Expression : 'Employee Id + LastName'}]";

            JsonMapping map = new JsonMapping(mapping);
            IEnumerable <ModelInstance> translatedInstances = translator.Translate(ModelContext.Current.GetModelType("Account"), outType, dynamicProvider.GetModelInstances(ModelContext.Current.GetModelType("TypeName")), map);

            Assert.AreEqual(translatedInstances.ElementAt(0)["firstName"], "MyNameIsJohn");
            Assert.AreEqual(translatedInstances.ElementAt(0)["lastName"], 3);
            Assert.AreEqual(translatedInstances.ElementAt(0)["accountNumber"], "1Doe");

            Assert.AreEqual(translatedInstances.ElementAt(1)["firstName"], "MyNameIsJohn");
            Assert.AreEqual(translatedInstances.ElementAt(1)["lastName"], 3);
            Assert.AreEqual(translatedInstances.ElementAt(1)["accountNumber"], "2Doe");
        }
Exemple #10
0
        public void TestArrayIndexPropertyPath()
        {
            ModelType      outType;
            IList <string> propertyNames = new List <string>();

            propertyNames.Add("Employee Id");
            propertyNames.Add("Location");
            propertyNames.Add("FirstName");
            propertyNames.Add("LastName");
            dynamicProvider.CreateType(propertyNames, out outType, "TypeName");

            //load a new instance
            IList <string> instanceValues = new List <string>();

            instanceValues.Add("1");
            instanceValues.Add("23");
            instanceValues.Add("John");
            instanceValues.Add("Doe");
            dynamicProvider.CreateInstance(outType, instanceValues);

            instanceValues = new List <string>();
            instanceValues.Add("2");
            instanceValues.Add("23");
            instanceValues.Add("Jane");
            instanceValues.Add("Doe");
            dynamicProvider.CreateInstance(outType, instanceValues);

            ModelType staticType = ModelContext.Current.GetModelType("Payment");

            Assert.AreEqual("Payment", staticType.Name);

            string mapping = @"[{PropertyPath : 'payments[0].amount',Expression : 'Employee Id'}]";

            JsonMapping map = new JsonMapping(mapping);
            IEnumerable <ModelInstance> translatedInstances = translator.Translate(ModelContext.Current.GetModelType("Account"), outType, dynamicProvider.GetModelInstances(ModelContext.Current.GetModelType("TypeName")), map);

            Assert.AreEqual(((ModelInstance)translatedInstances.ElementAt(0).GetList("payments").ElementAt(0))["amount"], "1");
            Assert.AreEqual(((ModelInstance)translatedInstances.ElementAt(1).GetList("payments").ElementAt(0))["amount"], "2");
        }
Exemple #11
0
 public Csv2SquidexConverter(string fields)
 {
     mapping = JsonMapping.ForCsv2Json(fields);
 }
 public Squidex2CsvConverter(string fields)
 {
     mapping = JsonMapping.ForJson2Csv(fields);
 }
 public JsonTransformation(JsonMapping mapping)
 {
     _mapping = mapping;
 }
Exemple #14
0
        public TObject GetWfmObjectFromJson <TObject>(Stream stream) where TObject : BaseWfmObject
        {
            var token = TokenizeIncomingJson(stream);

            return(JsonMapping.Parse <TObject>(token));
        }