示例#1
0
        private Category GetCategory(string categoryName, Definition definition, IDictionary <Guid, Category> categories)
        {
            if (categoryName == null)
            {
                // Use the definition's category.

                if (definition == null)
                {
                    return(null);
                }

                Category category;
                if (!categories.TryGetValue(definition.CategoryId, out category))
                {
                    category = _settingsQuery.GetCategory(definition.CategoryId);
                    categories[definition.CategoryId] = category;
                }

                return(category);
            }

            // An empty category name means do not use any category.

            if (categoryName.Length == 0)
            {
                return(null);
            }

            // Use the category name.

            return(_settingsQuery.GetCategory(categoryName));
        }
示例#2
0
        Communication ICampaignEmailsCommand.GeneratePreview(CampaignEmail email, Guid campaignId)
        {
            // Get the campaign.

            var campaign = _campaignsQuery.GetCampaign(campaignId);

            if (campaign == null)
            {
                throw new ApplicationException("Cannot find the campaign with id '" + campaignId + "'.");
            }

            email.Properties.Add("Category", campaign.CommunicationCategoryId == null ? "Campaign" : _settingsQuery.GetCategory(campaign.CommunicationCategoryId.Value).Name);
            email.Properties.Add("IncludeUnsubscribe", true);

            var template = _campaignsQuery.GetTemplate(campaign.Id);

            if (template != null)
            {
                // Create an item template based on it.

                var templateContentItem = CreateTemplateContentItem(campaign, template);
                return(_emailsCommand.GeneratePreview(email, templateContentItem));
            }

            return(_emailsCommand.GeneratePreview(email));
        }
示例#3
0
        private void Prepare(UnsubscribeRequestModel requestModel, UnsubscribeModel unsubscribeModel)
        {
            requestModel.Prepare();
            requestModel.Validate();

            // Get the user.

            var user = _usersQuery.GetUser(requestModel.UserId.Value);

            if (user == null)
            {
                throw new ValidationErrorsException(new NotFoundValidationError("UserId", requestModel.UserId.Value));
            }

            if (CurrentRegisteredUser == null)
            {
                unsubscribeModel.Login.LoginId = _loginCredentialsQuery.GetLoginId(requestModel.UserId.Value);
            }

            // Get the category.

            unsubscribeModel.Category = _settingsQuery.GetCategory(requestModel.Category);
            if (unsubscribeModel.Category == null)
            {
                throw new ValidationErrorsException(new NotFoundValidationError("Category", requestModel.Category));
            }
        }
示例#4
0
        private void UpdateSuggestedJobs(Guid memberId, bool sendSuggestedJobs)
        {
            try
            {
                var category  = _settingsQuery.GetCategory("SuggestedJobs");
                var settings  = _settingsQuery.GetSettings(memberId);
                var frequency = Frequency.Never;

                if (settings != null && settings.CategorySettings != null)
                {
                    var setting = settings.CategorySettings.FirstOrDefault(c => c.CategoryId == category.Id);

                    if (setting != null && setting.Frequency.HasValue)
                    {
                        frequency = setting.Frequency.Value;
                    }
                }

                var currentlySending = frequency != Frequency.Never;

                if (!sendSuggestedJobs && currentlySending)
                {
                    _settingsCommand.SetFrequency(memberId, category.Id, Frequency.Never);
                }
                else if (sendSuggestedJobs && !currentlySending)
                {
                    _settingsCommand.SetFrequency(memberId, category.Id, Frequency.Daily);
                }
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }
        }
示例#5
0
        private bool GetSuggestedJobSetting(Guid memberId)
        {
            var category = _settingsQuery.GetCategory("SuggestedJobs");
            var setting = _settingsQuery.GetSettings(memberId).CategorySettings.FirstOrDefault(c => c.CategoryId == category.Id);

            return (setting.Frequency != Frequency.Never);
        }
示例#6
0
        public void TestUnsubscribeEmailLink()
        {
            var administrator = _administratorAccountsCommand.CreateTestAdministrator(1);
            var campaign      = CreateCampaign(administrator);
            var member        = _memberAccountsCommand.CreateTestMember(0);

            // Send.

            var campaignEmail = _campaignEmailsCommand.CreateEmail(campaign, member);

            _campaignEmailsCommand.Send(new[] { campaignEmail }, campaign.Id, false);
            var email = _emailServer.AssertEmailSent();

            var category = _settingsQuery.GetCategory("Campaign");

            AssertUnsubscribeLink(member, category, email.GetHtmlView().GetLinks()[11]);
        }
示例#7
0
 public SuggestedJobsCreatorTask(ICandidatesWorkflowQuery candidatesWorkflowQuery, ISettingsQuery settingsQuery, ISettingsCommand settingsCommand)
     : base(Logger)
 {
     _candidatesWorkflowQuery = candidatesWorkflowQuery;
     _settingsQuery           = settingsQuery;
     _settingsCommand         = settingsCommand;
     _categoryId = _settingsQuery.GetCategory("SuggestedJobs").Id;
 }
示例#8
0
        public void TestInvitationEmailLinks()
        {
            var category = _settingsQuery.GetCategory("MemberToMemberNotification");

            // Create some members.

            var inviter = _memberAccountsCommand.CreateTestMember(EmailAddress);
            var invitee = _memberAccountsCommand.CreateTestMember(EmailAddress2);

            // Create an invitation.

            var invitation = new FriendInvitation {
                InviterId = inviter.Id, InviteeId = invitee.Id
            };

            // Check settings.

            AssertSettings(invitee, category, Frequency.Immediately);
            _memberFriendsCommand.SendInvitation(invitation);
            var email = _emailServer.AssertEmailSent();

            AssertUnsubscribeLink(invitee, category, email.GetHtmlView().GetLinks()[3]);

            // Accept the invitation.

            AssertSettings(inviter, category, Frequency.Immediately);
            _memberFriendsCommand.AcceptInvitation(invitee.Id, invitation);
            email = _emailServer.AssertEmailSent();
            AssertUnsubscribeLink(invitee, category, email.GetHtmlView().GetLinks()[3]);
        }
示例#9
0
        public ActionResult New()
        {
            // Show a new campaign with the default communication category set.

            var campaign = new Campaign
            {
                CommunicationCategoryId = _settingsQuery.GetCategory("Campaign").Id,
            };

            return(View(new CampaignSummaryModel {
                Campaign = campaign, CreatedBy = CurrentRegisteredUser, IsReadOnly = false, CommunicationDefinitions = _settingsQuery.GetDefinitions(), CommunicationCategories = _settingsQuery.GetCategories()
            }));
        }
示例#10
0
        private void UpdateSuggestedJobs(Guid memberId, bool sendSuggestedJobs)
        {
            var category = _settingsQuery.GetCategory("SuggestedJobs");
            var setting  = _settingsQuery.GetSettings(memberId).CategorySettings.Where(c => c.CategoryId == category.Id).FirstOrDefault();

            var currentlySending = setting.Frequency != Frequency.Never;

            if (!sendSuggestedJobs && currentlySending)
            {
                _settingsCommand.SetFrequency(memberId, category.Id, Frequency.Never);
            }
            else if (sendSuggestedJobs && !currentlySending)
            {
                _settingsCommand.SetFrequency(memberId, category.Id, Frequency.Daily);
            }
        }
        public SuggestedJobsWorkflowSubscriber(IChannelManager <IService> proxyManager, ICandidatesQuery candidatesQuery, ISettingsQuery settingsQuery, ISettingsCommand settingsCommand)
        {
            _proxyManager    = proxyManager;
            _candidatesQuery = candidatesQuery;
            _settingsQuery   = settingsQuery;
            _settingsCommand = settingsCommand;

            Category category = _settingsQuery.GetCategory("SuggestedJobs");

            if (category == null)
            {
                throw new InvalidOperationException("The 'SuggestedJobs' category is not defined.");
            }

            _categoryId = category.Id;
        }
示例#12
0
        private void AssertSuggestedJobs(bool expectedSendSuggestedJobs, Guid memberId)
        {
            var category  = _settingsQuery.GetCategory("SuggestedJobs");
            var frequency = Frequency.Never;
            var settings  = _settingsQuery.GetSettings(memberId);

            if (settings != null)
            {
                var setting = settings.CategorySettings.Where(c => c.CategoryId == category.Id).FirstOrDefault();

                if (setting != null && setting.Frequency.HasValue)
                {
                    frequency = setting.Frequency.Value;
                }
            }

            Assert.AreEqual(expectedSendSuggestedJobs, frequency != Frequency.Never);
        }
示例#13
0
        private bool GetSuggestedJobsEmailSetting(Guid memberId)
        {
            var category  = _settingsQuery.GetCategory("SuggestedJobs");
            var settings  = _settingsQuery.GetSettings(memberId);
            var frequency = Frequency.Never;

            if (settings != null && settings.CategorySettings != null)
            {
                var setting = settings.CategorySettings.FirstOrDefault(c => c.CategoryId == category.Id);

                if (setting != null && setting.Frequency.HasValue)
                {
                    frequency = setting.Frequency.Value;
                }
            }

            return(frequency != Frequency.Never);
        }
示例#14
0
        private void AssertCategory(string name, Frequency?expectedFrequency, RecipientSettings settings)
        {
            var category = _settingsQuery.GetCategory(name);

            if (expectedFrequency == null)
            {
                if (settings != null)
                {
                    Assert.IsNull((from c in settings.CategorySettings where c.CategoryId == category.Id select c).SingleOrDefault());
                }
            }
            else
            {
                Assert.IsNotNull(settings);
                var categorySettings = (from c in settings.CategorySettings where c.CategoryId == category.Id select c).SingleOrDefault();
                Assert.IsNotNull(categorySettings);
                Assert.AreEqual(expectedFrequency.Value, categorySettings.Frequency);
            }
        }
示例#15
0
        protected void CreateCampaign(int index, CampaignCategory category, string query, out Campaign campaign, out Template template)
        {
            campaign = new Campaign
            {
                Id                      = Guid.NewGuid(),
                Name                    = string.Format(CampaignNameFormat, index),
                CreatedBy               = Guid.NewGuid(),
                CreatedTime             = DateTime.Now.AddMinutes(index),
                Category                = category,
                CommunicationCategoryId = _settingsQuery.GetCategory("Campaign").Id,
                Query                   = query,
            };

            _campaignsCommand.CreateCampaign(campaign);

            template = new Template
            {
                Subject = string.Format(TemplateSubjectFormat, index),
                Body    = string.Format(TemplateBodyFormat, index)
            };
            _campaignsCommand.CreateTemplate(campaign.Id, template);
        }
 public EmailEmployerNewsletterTaskTests()
 {
     _category = _settingsQuery.GetCategory("EmployerUpdate");
 }
示例#17
0
 private Category GetCategory()
 {
     return(_settingsQuery.GetCategory("MemberToMemberNotification"));
 }
示例#18
0
 public void TestNotificationFrequencies()
 {
     Assert.IsTrue(_settingsQuery.GetCategory("MemberToMemberNotification").AvailableFrequencies.SequenceEqual(new[] { Frequency.Immediately, Frequency.Never }));
 }
示例#19
0
        protected void GetBodyEnd(TemplateEmail email, ICommunicationUser to, StringBuilder sb)
        {
            sb.AppendLine("      </div>");

            if (to != null)
            {
                if (to is Member)
                {
                    sb.AppendLine("      <div class=\"signature\" style=\"padding-left: 9px; font-family: Arial, Helvetica, sans-serif; color: gray; font-size: 9pt; padding-top:1em;\">");
                    GetMemberSignature(email, sb);
                    sb.AppendLine("      </div>");
                    sb.AppendLine();
                }
                else if (to is IEmployer)
                {
                    sb.AppendLine("      <div class=\"signature\" style=\"padding-left: 9px; font-family: Arial, Helvetica, sans-serif; color: gray; font-size: 9pt; padding-top:1em;\">");
                    GetClientSignature(email, sb);
                    sb.AppendLine("      </div>");
                }
                else if (to is Custodian)
                {
                    sb.AppendLine("      <div class=\"signature\" style=\"padding-left: 9px; font-family: Arial, Helvetica, sans-serif; color: gray; font-size: 9pt; padding-top:1em;\">");
                    GetCommunitySignature(sb);
                    sb.AppendLine("      </div>");
                }
            }

            string category   = null;
            var    definition = _settingsQuery.GetDefinition(email.Definition);

            if (definition != null)
            {
                category = _settingsQuery.GetCategory(definition.CategoryId).Name;
            }

            if (category != null && to is Member && to.FirstName != null)
            {
                sb.AppendLine("      <div class=\"unsubscribe\" style=\"padding-left: 9px; font-family: Arial, Helvetica, sans-serif; color: gray; font-size: 8pt; padding-top:1em; margin-left: 20px;\">");
                sb.AppendLine("        <p>");
                sb.AppendLine("          Receiving too many emails?");
                sb.AppendLine("          <br />");
                sb.AppendLine("          <a href=\"" + GetTinyUrl(email, true, "~/members/settings") + "\">");
                sb.AppendLine("            Log in");
                sb.AppendLine("          </a>");
                sb.AppendLine("          to choose the emails you receive from us.");
                sb.AppendLine("        </p>");
                sb.AppendLine("        <p>");
                sb.AppendLine("          Alternatively, you can");
                sb.AppendLine("          <a href=\"" + GetTinyUrl(email, false, "~/accounts/settings/unsubscribe", "userId", to.Id.ToString("n"), "category", category) + "\">");
                sb.AppendLine("            unsubscribe");
                sb.AppendLine("          </a>");
                sb.AppendLine("          from this type of email entirely.");
                sb.AppendLine("        </p>");
                sb.AppendLine("      </div>");
                sb.AppendLine();
            }

            sb.AppendLine("    </div>");
            sb.AppendLine("    <img src=\"" + GetTrackingPixelUrl(email) + "\" width=\"1\" height=\"1\" />");
            sb.AppendLine("  </body>");
            sb.AppendLine("</html>");
        }