public static coreModel.Promotion ToCoreModel(this webModel.Promotion promotion) { var retVal = new DynamicPromotion(); retVal.InjectFrom(promotion); retVal.Coupons = promotion.Coupons; if (promotion.DynamicExpression != null && promotion.DynamicExpression.Children != null) { var conditionExpression = promotion.DynamicExpression.GetConditionExpression(); retVal.PredicateSerialized = SerializationUtil.SerializeExpression(conditionExpression); var rewards = promotion.DynamicExpression.GetRewards(); retVal.RewardsSerialized = JsonConvert.SerializeObject(rewards, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }); //Clear availableElements in expression (for decrease size) promotion.DynamicExpression.AvailableChildren = null; var allBlocks = ((DynamicExpression)promotion.DynamicExpression).Traverse(x => x.Children); foreach(var block in allBlocks) { block.AvailableChildren = null; } retVal.PredicateVisualTreeSerialized = JsonConvert.SerializeObject(promotion.DynamicExpression); } return retVal; }
/// <summary> /// Converting to model type /// </summary> /// <param name="catalogBase"></param> /// <returns></returns> public static coreModel.Promotion ToCoreModel(this dataModel.Promotion dbEntity) { if (dbEntity == null) throw new ArgumentNullException("dbEntity"); var retVal = new DynamicPromotion(); retVal.InjectFrom(dbEntity); retVal.Coupons = dbEntity.Coupons.Select(x=>x.Code).ToArray(); retVal.Store = dbEntity.StoreId; retVal.MaxUsageCount = dbEntity.TotalLimit; retVal.MaxPersonalUsageCount = dbEntity.PerCustomerLimit; return retVal; }