示例#1
0
        public void Execute(OrderLine orderLine)
        {
            if (orderLine == null || orderLine.ProductVariant == null || string.IsNullOrWhiteSpace(orderLine.Data))
            {
                return;
            }
            ProductVariant productVariant = orderLine.ProductVariant;

            if (productVariant.IsGiftCard)
            {
                // ensure that duplicate cards aren't generated
                if (orderLine.GiftCards.Any())
                {
                    return;
                }
                try
                {
                    var giftCardInfo = JsonConvert.DeserializeObject <GiftCardInfo>(orderLine.Data);

                    var giftCard = new GiftCard
                    {
                        Code           = _generateGiftCardCode.Generate(),
                        GiftCardType   = productVariant.GiftCardType,
                        Message        = giftCardInfo.Message,
                        RecipientEmail = giftCardInfo.RecipientEmail,
                        RecipientName  = giftCardInfo.RecipientName,
                        SenderEmail    = giftCardInfo.SenderEmail,
                        SenderName     = giftCardInfo.SenderName,
                        Value          = orderLine.Price,
                        OrderLine      = orderLine,
                    };
                    orderLine.GiftCards.Add(giftCard);
                    _session.Transact(session => session.Save(giftCard));
                }
                catch (Exception exception)
                {
                    CurrentRequestData.ErrorSignal.Raise(exception);
                }
            }
        }
 public string GenerateCode()
 {
     return(_generateGiftCardCode.Generate());
 }