public virtual async Task NotifyRecipient(GiftVoucher giftVoucher, GiftVoucherModel model) { model = giftVoucher.ToModel(_dateTimeService); var order = await FillGiftVoucherModel(giftVoucher, model); var languageId = ""; if (order != null) { var customerLang = await _languageService.GetLanguageById(order.CustomerLanguageId); if (customerLang == null) { customerLang = (await _languageService.GetAllLanguages()).FirstOrDefault(); } if (customerLang != null) { languageId = customerLang.Id; } } else { languageId = _languageSettings.DefaultAdminLanguageId; } int queuedEmailId = await _messageProviderService.SendGiftVoucherMessage(giftVoucher, order, languageId); if (queuedEmailId > 0) { giftVoucher.IsRecipientNotified = true; await _giftVoucherService.UpdateGiftVoucher(giftVoucher); model.IsRecipientNotified = true; } }
public async Task <bool> Handle(ActivatedValueForPurchasedGiftVouchersCommand request, CancellationToken cancellationToken) { if (request.Order == null) { throw new ArgumentNullException(nameof(request.Order)); } foreach (var orderItem in request.Order.OrderItems) { var giftVouchers = await _giftVoucherService.GetAllGiftVouchers(purchasedWithOrderItemId : orderItem.Id, isGiftVoucherActivated : !request.Activate); foreach (var gc in giftVouchers) { if (request.Activate) { //activate bool isRecipientNotified = gc.IsRecipientNotified; if (gc.GiftVoucherTypeId == GiftVoucherType.Virtual) { //send email for virtual gift voucher if (!String.IsNullOrEmpty(gc.RecipientEmail) && !String.IsNullOrEmpty(gc.SenderEmail)) { var customerLang = await _languageService.GetLanguageById(request.Order.CustomerLanguageId); if (customerLang == null) { customerLang = (await _languageService.GetAllLanguages()).FirstOrDefault(); } if (customerLang == null) { throw new Exception("No languages could be loaded"); } int queuedEmailId = await _messageProviderService.SendGiftVoucherMessage(gc, request.Order, customerLang.Id); if (queuedEmailId > 0) { isRecipientNotified = true; } } } gc.IsGiftVoucherActivated = true; gc.IsRecipientNotified = isRecipientNotified; await _giftVoucherService.UpdateGiftVoucher(gc); } else { //deactivate gc.IsGiftVoucherActivated = false; await _giftVoucherService.UpdateGiftVoucher(gc); } } } return(true); }