Exemple #1
0
func FactoryPromotion(rep promotion.IPromotionRep, saleRep sale.ISaleRep,
	v *promotion.ValuePromotion) promotion.IPromotion {
	prom := newPromotion(rep, saleRep, v)

	if prom.Type() == promotion.TypeFlagCashBack {
		pv := rep.GetValueCashBack(prom.GetAggregateRootId())
		if pv == nil {
			pv = &promotion.ValueCashBack{
				Id: prom.GetAggregateRootId(),
			}
		}
		cp := &CashBackPromotion{
			Promotion:      prom,
			_cashBackValue: pv,
		}
		return cp
	}

	//todo:
	return prom
}
Exemple #2
0
func DeletePromotion(p promotion.IPromotion) error {
	var err error
	var rep promotion.IPromotionRep = nil
	if p.Type() == promotion.TypeFlagCashBack {
		v := p.(*CashBackPromotion)
		rep = v._promRep
		err = rep.DeleteValueCashBack(v.GetAggregateRootId())
	} else if p.Type() == promotion.TypeFlagCoupon {
		v := p.(*Coupon)
		rep = v._promRep
		err = rep.DeleteValueCoupon(v.GetAggregateRootId())
	}
	if err == nil && rep != nil {
		err = rep.DeletePromotion(p.GetAggregateRootId())
	}
	return err
}