Esempio n. 1
0
        public virtual async Task TryToSendOrderNotificationsAsync(OrderNotificationJobArgument[] jobArguments)
        {
            var ordersByIdDict = (await _customerOrderService.GetAsync(jobArguments.Select(x => x.CustomerOrderId).Distinct().ToList()))
                                 .ToDictionary(x => x.Id)
                                 .WithDefaultValue(null);

            foreach (var jobArgument in jobArguments)
            {
                var notification = await _notificationSearchService.GetNotificationAsync(jobArgument.NotificationTypeName, new TenantIdentity(jobArgument.StoreId, nameof(Store)));

                if (notification != null)
                {
                    var order = ordersByIdDict[jobArgument.CustomerOrderId];

                    if (order != null && notification is CustomerReviewEmailNotification orderNotification)
                    {
                        var customer = await _memberResolver.ResolveMemberByIdAsync(jobArgument.CustomerId);

                        orderNotification.Item         = order.Items.FirstOrDefault(i => i.ProductId == jobArgument.ProductId);
                        orderNotification.Customer     = customer;
                        orderNotification.RequestId    = jobArgument.RequestId;
                        orderNotification.LanguageCode = order.LanguageCode;

                        await SetNotificationParametersAsync(notification, order, customer);

                        await _notificationSender.ScheduleSendNotificationAsync(notification);
                    }
                }
            }
        }
        public async Task <ActionResult> ScheduleSendNotification([FromBody] Notification notificationRequest)
        {
            var notification = await _notificationSearchService.GetNotificationAsync(notificationRequest.Type, notificationRequest.TenantIdentity);

            await _notificationSender.ScheduleSendNotificationAsync(notification.PopulateFromOther(notificationRequest));

            return(Ok());
        }