Ejemplo n.º 1
0
 public HttpStatusCode SubmitSubscriptions(ImportedCustomer[] importedCustomers)
 {
     _importCustomer.SubmitSubscriptions(importedCustomers);
     return HttpStatusCode.OK;
 }
Ejemplo n.º 2
0
        public void SubmitSubscriptions(ImportedCustomer[] importedCustomers)
        {
            var commandService = _quartetClientFactory.GetCommandServiceClient();
            var queryService   = _quartetClientFactory.GetCustomersQueryServiceClient();

            foreach (var importedCustomer in importedCustomers)
            {
                var customer = queryService.GetCustomer(importedCustomer.CustomerId);
                if (customer == null)
                    continue;

                foreach (var subscription in importedCustomer.Subscriptions)
                {
                    var customerSubscription = customer.Subscriptions.Select(s => s.Value).Where(s => s.SubscriptionType == subscription.SubscriptionType).FirstOrDefault();
                    if
                        (customerSubscription != null &&
                        (customerSubscription.SubscriptionStatus != subscription.SubscriptionStatus) ||
                        (subscription.SubscriptionStatus == Quartet.Entities.SubscriptionStatus.OptedIn &&
                        customerSubscription == null))
                    {
                        var command = new QuartetCommands.UpdateCustomerSubscription
                        {
                            CustomerId         = subscription.CustomerId,
                            SubscriptionType   = subscription.SubscriptionType,
                            SubscriptionStatus = subscription.SubscriptionStatus,
                            SubscribedCulture  = customer.ContactPreferences.PreferredLanguage ?? "en-US"
                        };

                        commandService.Execute<QuartetCommands.UpdateCustomerSubscription>(command);
                    }
                }
            }
        }