public static SeedDiscrepancyViewModel FromModel(SeedDiscrepancy discrepancy)
        {
            return new SeedDiscrepancyViewModel()
            {
                EmailAddress = discrepancy.EmailAddress,
                FirstName = discrepancy.FirstName,
                LastName = discrepancy.LastName,
                DOB = discrepancy.DOB,
                Gender = discrepancy.Gender,
                City = discrepancy.City,
                State = discrepancy.State,
                Country = discrepancy.Country,
                ZipCode = discrepancy.ZipCode,
                Description = discrepancy.Description,
                AccountId = discrepancy.Account.HasValue ? (int?)discrepancy.Account.Value.AccountId : null,
                ProviderId = discrepancy.Account.HasValue ? (int?)discrepancy.Account.Value.ProviderId : null,
                ServerId = discrepancy.Account.HasValue ? (int?)discrepancy.Account.Value.ServerId : null,
                IsActive = discrepancy.Account.HasValue ? (bool?)discrepancy.Account.Value.IsActive : null,
                AccountDateCreated = discrepancy.Account.HasValue ? (DateTime?)discrepancy.Account.Value.DateAccountCreated : null,
                LastEngagedDate = discrepancy.Account.HasValue ? discrepancy.Account.Value.LastEngagedDate : null,
                SubscriberId = discrepancy.Subscriber.HasValue ? (int?)discrepancy.Subscriber.Value.SubscriberId : null,
                IsMailable = discrepancy.Subscriber.HasValue ? (bool?)discrepancy.Subscriber.Value.IsMailable : null,
                SubscriberDateCreated = discrepancy.Subscriber.HasValue ? (DateTime?)discrepancy.Subscriber.Value.DateCreated : null
            };

        }
Beispiel #2
0
        public async Task<bool> AddSubscriber(SeedDiscrepancy discrepancy)
        {
            var emailAddress = discrepancy.EmailAddress;
            var subscriberInStore = (await GetSubscribers(x => x.email.Trim() == emailAddress)).SingleOrDefault();

            if (subscriberInStore != null)
            {
                return await this.Update(subscriberInStore.SetMailable());
            }
            else
            {
                return await this.Add
                (
                    discrepancy
                        .ToSubscriber()
                        .SetMailable()
                        .Set(x => x.insertionDate, DateTime.Now)
                );
            }
        }
Beispiel #3
0
 public async Task<bool> EnableSubscriber(SeedDiscrepancy discrepancy)
 {
     return await this.Update(discrepancy.ToSubscriber().SetMailable());
 }
Beispiel #4
0
        public async Task<SeedDiscrepancyResolution> Resolve(SeedDiscrepancy discrepancy)
        {
            if (!discrepancy.IsValid)
            {
                return SeedDiscrepancyResolution.Failed(discrepancy).WithMessage(SeedDiscrepancy.InvalidDiscrepancyMessage);
            }

            var result = SeedDiscrepancyResolution.Failed(discrepancy).WithMessage(SeedDiscrepancy.NotImplementedFeatureMessage);

            if (discrepancy.IsEngagerDiscrepancy)
            {
                using (var subscribersCtx = new SubscribersContext())
                {
                    var provider = WD40.Domain.Engagement.Providers.Registry.Instance[discrepancy.Account.Value.ProviderId];
                    var metadata = await GetMetadataForProviderAsync(provider.SubscriberId);

                    if (!discrepancy.Subscriber.HasValue)
                    {
                        try
                        {
                            result.Succeeded = await subscribersCtx.FromStore(metadata.DatabaseName, metadata.TableName).AddSubscriber(discrepancy);
                            result.WithMessage(SeedDiscrepancy.ResolvedMessage);
                        }
                        catch (Exception e)
                        {
                            result.WithMessage(e.Message);
                        }
                    }
                    else
                    {
                        try
                        {
                            result.Succeeded = await subscribersCtx.FromStore(metadata.DatabaseName, metadata.TableName).EnableSubscriber(discrepancy);
                            result.WithMessage(SeedDiscrepancy.ResolvedMessage);
                        }
                        catch (Exception e)
                        {
                            result.WithMessage(e.Message);
                        }
                    }
                }
            }
            else
            {
                if (!discrepancy.Account.HasValue)
                {
                    // TODO: Add subscriber to Engager
                    throw new NotImplementedException(result.Messages);
                }
                else
                {
                    // TODO: Update account in Engager with active = true
                    throw new NotImplementedException(result.Messages);
                }
            }

            return result;
        }