Пример #1
0
        public static dataModel.Promotion ToDataModel(this coreModel.Promotion promotion)
        {
            if (promotion == null)
            {
                throw new ArgumentNullException("promotion");
            }

            var retVal = new dataModel.Promotion();

            retVal.StartDate = DateTime.UtcNow;
            retVal.InjectFrom(promotion);

            retVal.StartDate = promotion.StartDate ?? DateTime.UtcNow;
            retVal.StoreId   = promotion.Store;
            if (promotion.Coupons != null)
            {
                retVal.Coupons = new ObservableCollection <dataModel.Coupon>(promotion.Coupons.Select(x => new dataModel.Coupon {
                    Code = x
                }));
            }
            retVal.TotalLimit       = promotion.MaxUsageCount;
            retVal.PerCustomerLimit = promotion.MaxPersonalUsageCount;

            return(retVal);
        }
Пример #2
0
        public static webModel.Promotion ToWebModel(this coreModel.Promotion promotion)
        {
            var retVal = new webModel.Promotion();

            retVal.InjectFrom(promotion);
            return(retVal);
        }
Пример #3
0
        public static webModel.Promotion ToWebModel(this coreModel.Promotion promotion, PromoDynamicExpressionTree etalonEpressionTree = null)
        {
            var retVal = new webModel.Promotion();

            retVal.InjectFrom(promotion);
            retVal.Coupons = promotion.Coupons;
            retVal.Type    = promotion.GetType().Name;
            var dynamicPromotion = promotion as DynamicPromotion;

            if (dynamicPromotion != null && etalonEpressionTree != null)
            {
                retVal.DynamicExpression = etalonEpressionTree;
                if (!String.IsNullOrEmpty(dynamicPromotion.PredicateVisualTreeSerialized))
                {
                    retVal.DynamicExpression = JsonConvert.DeserializeObject <PromoDynamicExpressionTree>(dynamicPromotion.PredicateVisualTreeSerialized);
                    //Copy available elements from etalon because they not persisted
                    var sourceBlocks = ((DynamicExpression)etalonEpressionTree).Traverse(x => x.Children);
                    var targetBlocks = ((DynamicExpression)retVal.DynamicExpression).Traverse(x => x.Children);
                    foreach (var sourceBlock in sourceBlocks)
                    {
                        foreach (var targetBlock in  targetBlocks.Where(x => x.Id == sourceBlock.Id))
                        {
                            targetBlock.AvailableChildren = sourceBlock.AvailableChildren;
                        }
                    }
                    //copy available elements from etalon
                    retVal.DynamicExpression.AvailableChildren = etalonEpressionTree.AvailableChildren;
                }
            }
            return(retVal);
        }
		public void RegisterPromotion(Promotion promotion)
		{
			if (promotion == null)
			{
				throw new ArgumentNullException("promotion");
			}
			if (_promotions.Any(x => x.Id == promotion.Id))
			{
				throw new OperationCanceledException(promotion.Id + " already registered");
			}
			_promotions.Add(promotion);
		}
        public Promotion CreatePromotion(Promotion promotion)
        {
            var entity = promotion.ToDataModel();

            coreModel.Promotion retVal = null;
            using (var repository = _repositoryFactory())
            {
                repository.Add(entity);
                CommitChanges(repository);
            }
            retVal = GetPromotionById(entity.Id);
            return(retVal);
        }
Пример #6
0
        public Promotion CreatePromotion(Promotion promotion)
        {
            var entity = promotion.ToDataModel();

            coreModel.Promotion retVal = null;
            using (var repository = _repositoryFactory())
            {
                repository.Add(entity);
                CommitChanges(repository);
            }
            retVal = GetPromotionById(entity.Id);
            _cacheManager.ClearRegion("MarketingModuleRegion");
            return(retVal);
        }
Пример #7
0
        public Promotion GetPromotionById(string id)
        {
            coreModel.Promotion retVal = null;
            using (var repository = _repositoryFactory())
            {
                var entity = repository.GetPromotionById(id);

                if (entity != null)
                {
                    retVal = entity.ToCoreModel();
                }
            }

            if (retVal == null)
            {
                retVal = _customPromotionManager.Promotions.FirstOrDefault(x => x.Id == id);
            }
            return(retVal);
        }
 public CatalogPromotionResult(Promotion promo)
 {
     CatalogPromotionId = promo.Name;
     Description        = promo.Description;
 }
		public CatalogPromotionResult(Promotion promo)
		{
			CatalogPromotionId = promo.Name;
			Description = promo.Description;
		}