예제 #1
0
        public virtual async Task NotifyRecipient(GiftCard giftCard, GiftCardModel model)
        {
            model = giftCard.ToModel();
            var order = await FillGiftCardModel(giftCard, 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 = _localizationSettings.DefaultAdminLanguageId;
            }
            int queuedEmailId = await _workflowMessageService.SendGiftCardNotification(giftCard, languageId);

            if (queuedEmailId > 0)
            {
                giftCard.IsRecipientNotified = true;
                await _giftCardService.UpdateGiftCard(giftCard);

                model.IsRecipientNotified = true;
            }
        }
        /// <summary>
        /// Prepare gift card model
        /// </summary>
        /// <param name="model">Gift card model</param>
        /// <param name="giftCard">Gift card</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the gift card model
        /// </returns>
        public virtual async Task <GiftCardModel> PrepareGiftCardModelAsync(GiftCardModel model, GiftCard giftCard, bool excludeProperties = false)
        {
            if (giftCard != null)
            {
                //fill in model values from the entity
                model ??= giftCard.ToModel <GiftCardModel>();

                var order = await _orderService.GetOrderByOrderItemAsync(giftCard.PurchasedWithOrderItemId ?? 0);

                model.PurchasedWithOrderId = order?.Id;
                model.RemainingAmountStr   = await _priceFormatter.FormatPriceAsync(await _giftCardService.GetGiftCardRemainingAmountAsync(giftCard), true, false);

                model.AmountStr = await _priceFormatter.FormatPriceAsync(giftCard.Amount, true, false);

                model.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(giftCard.CreatedOnUtc, DateTimeKind.Utc);

                model.PurchasedWithOrderNumber = order?.CustomOrderNumber;

                //prepare nested search model
                PrepareGiftCardUsageHistorySearchModel(model.GiftCardUsageHistorySearchModel, giftCard);
            }

            model.PrimaryStoreCurrencyCode = (await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId))?.CurrencyCode;

            return(model);
        }
        public virtual void NotifyRecipient(GiftCard giftCard, GiftCardModel model)
        {
            model = giftCard.ToModel();
            var order      = FillGiftCardModel(giftCard, model);
            var languageId = "";

            if (order != null)
            {
                var customerLang = _languageService.GetLanguageById(order.CustomerLanguageId);
                if (customerLang == null)
                {
                    customerLang = _languageService.GetAllLanguages().FirstOrDefault();
                }
                if (customerLang != null)
                {
                    languageId = customerLang.Id;
                }
            }
            else
            {
                languageId = Grand.Core.Infrastructure.EngineContext.Current.Resolve <LocalizationSettings>().DefaultAdminLanguageId;
            }
            int queuedEmailId = _workflowMessageService.SendGiftCardNotification(giftCard, languageId);

            if (queuedEmailId > 0)
            {
                giftCard.IsRecipientNotified = true;
                _giftCardService.UpdateGiftCard(giftCard);
                model.IsRecipientNotified = true;
            }
        }
예제 #4
0
        public virtual async Task <GiftCardModel> PrepareGiftCardModel(GiftCard giftCard)
        {
            var   model = giftCard.ToModel();
            Order order = null;

            if (giftCard.PurchasedWithOrderItem != null)
            {
                order = await _orderService.GetOrderByOrderItemId(giftCard.PurchasedWithOrderItem.Id);
            }

            var currency = await _currencyService.GetCurrencyByCode(giftCard.CurrencyCode);

            if (currency == null)
            {
                currency = await _currencyService.GetPrimaryStoreCurrency();
            }

            model.PurchasedWithOrderId     = giftCard.PurchasedWithOrderItem != null ? order?.Id : null;
            model.PurchasedWithOrderNumber = order?.OrderNumber ?? 0;
            model.RemainingAmountStr       = _priceFormatter.FormatPrice(giftCard.GetGiftCardRemainingAmount(), true, currency, _workContext.WorkingLanguage, true, false);
            model.AmountStr    = _priceFormatter.FormatPrice(giftCard.Amount, true, currency, _workContext.WorkingLanguage, true, false);
            model.CreatedOn    = _dateTimeHelper.ConvertToUserTime(giftCard.CreatedOnUtc, DateTimeKind.Utc);
            model.CurrencyCode = giftCard.CurrencyCode;
            return(model);
        }
        public virtual GiftCardModel PrepareGiftCardModel(GiftCard giftCard)
        {
            var   model = giftCard.ToModel();
            Order order = null;

            if (giftCard.PurchasedWithOrderItem != null)
            {
                order = _orderService.GetOrderByOrderItemId(giftCard.PurchasedWithOrderItem.Id);
            }

            model.PurchasedWithOrderId     = giftCard.PurchasedWithOrderItem != null ? order?.Id : null;
            model.PurchasedWithOrderNumber = order?.OrderNumber ?? 0;
            model.RemainingAmountStr       = _priceFormatter.FormatPrice(giftCard.GetGiftCardRemainingAmount(), true, false);
            model.AmountStr = _priceFormatter.FormatPrice(giftCard.Amount, true, false);
            model.CreatedOn = _dateTimeHelper.ConvertToUserTime(giftCard.CreatedOnUtc, DateTimeKind.Utc);
            model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
            return(model);
        }
예제 #6
0
        /// <summary>
        /// Prepare gift card model
        /// </summary>
        /// <param name="model">Gift card model</param>
        /// <param name="giftCard">Gift card</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Gift card model</returns>
        public virtual GiftCardModel PrepareGiftCardModel(GiftCardModel model, GiftCard giftCard, bool excludeProperties = false)
        {
            if (giftCard != null)
            {
                //fill in model values from the entity
                model = model ?? giftCard.ToModel();

                model.PurchasedWithOrderId     = giftCard.PurchasedWithOrderItem?.OrderId;
                model.RemainingAmountStr       = _priceFormatter.FormatPrice(giftCard.GetGiftCardRemainingAmount(), true, false);
                model.AmountStr                = _priceFormatter.FormatPrice(giftCard.Amount, true, false);
                model.CreatedOn                = _dateTimeHelper.ConvertToUserTime(giftCard.CreatedOnUtc, DateTimeKind.Utc);
                model.PurchasedWithOrderNumber = giftCard.PurchasedWithOrderItem?.Order?.CustomOrderNumber;

                //prepare nested search model
                PrepareGiftCardUsageHistorySearchModel(model.GiftCardUsageHistorySearchModel, giftCard);
            }

            model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId)?.CurrencyCode;

            return(model);
        }