Esempio n. 1
0
        public ActionResult Communications()
        {
            var member   = CurrentMember;
            var settings = _settingsQuery.GetSettings(User.Id().Value);

            try
            {
                var categories = _settingsQuery.GetCategories(UserType.Member);

                // Dynamically determine what has been changed.

                foreach (var category in (from c in categories where c.Timing == Timing.Periodic select c))
                {
                    var frequency = GetValue <Frequency>(category.Name);

                    // If the value has changed then update the database.

                    var currentFrequency = GetFrequency(category.Id, settings);
                    if (currentFrequency != frequency)
                    {
                        _settingsCommand.SetFrequency(member.Id, category.Id, frequency);
                    }
                }

                foreach (var category in (from c in categories where c.Timing == Timing.Notification select c))
                {
                    var frequency = IsChecked(category.Name) ? Frequency.Immediately : Frequency.Never;

                    // If the value has changed then update the database.

                    var currentFrequency = GetFrequency(category.Id, settings);
                    if (currentFrequency != frequency)
                    {
                        _settingsCommand.SetFrequency(member.Id, category.Id, frequency);
                    }
                }

                return(RedirectToReturnUrlWithConfirmation("Your changes have been saved."));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            var primaryEmailAddress   = member.GetPrimaryEmailAddress();
            var secondaryEmailAddress = member.GetSecondaryEmailAddress();

            var settingsModel = new SettingsModel
            {
                CanEditContactDetails = CanEditContactDetails(),
                FirstName             = member.FirstName,
                LastName              = member.LastName,
                EmailAddress          = primaryEmailAddress == null ? null : primaryEmailAddress.Address,
                SecondaryEmailAddress = secondaryEmailAddress == null ? null : secondaryEmailAddress.Address,
            };

            UpdateCategories(settingsModel, settings);

            return(View("Settings", settingsModel));
        }
Esempio n. 2
0
        public ActionResult Communications(Guid id)
        {
            var organisation = _organisationsQuery.GetOrganisation(id);

            if (organisation == null)
            {
                return(NotFound("organisation", "id", id));
            }

            var settings   = _settingsQuery.GetSettings(organisation.Id);
            var categories = _settingsQuery.GetCategories(UserType.Employer);

            return(View(GetCommunicationsModel(organisation, settings, categories)));
        }
Esempio n. 3
0
        public ActionResult Settings()
        {
            var employer = CurrentEmployer;

            var credentials = _loginCredentialsQuery.GetCredentials(employer.Id);

            var jobPoster = _jobPostersQuery.GetJobPoster(employer.Id) ?? new JobPoster {
                Id = employer.Id
            };
            var nonMemberSettings = _nonMemberSettingsQuery.GetNonMemberSettings(employer.EmailAddress.Address);

            var settings = _settingsQuery.GetSettings(employer.Id);
            var employerUpdateCategory = (from c in _settingsQuery.GetCategories(UserType.Employer) where c.Name == "EmployerUpdate" select c).Single();
            var campaignCategory       = (from c in _settingsQuery.GetCategories(UserType.Employer) where c.Name == "Campaign" select c).Single();

            var model = new SettingsModel
            {
                FirstName               = employer.FirstName,
                LastName                = employer.LastName,
                OrganisationName        = employer.Organisation.Name,
                CanEditOrganisationName = !employer.Organisation.IsVerified,
                Role                       = employer.SubRole,
                JobTitle                   = employer.JobTitle,
                EmailAddress               = employer.EmailAddress.Address,
                PhoneNumber                = employer.PhoneNumber == null ? null : employer.PhoneNumber.Number,
                IndustryIds                = employer.Industries == null ? new List <Guid>() : employer.Industries.Select(i => i.Id).ToList(),
                Industries                 = _industriesQuery.GetIndustries(),
                HasLoginCredentials        = credentials != null,
                LoginId                    = credentials == null ? null : credentials.LoginId,
                UseLinkedInProfile         = _linkedInQuery.GetProfile(employer.Id) != null,
                Allocations                = GetAllocations(employer),
                ShowSuggestedCandidates    = jobPoster.ShowSuggestedCandidates,
                SendSuggestedCandidates    = jobPoster.SendSuggestedCandidates,
                ReceiveSuggestedCandidates = nonMemberSettings == null || !nonMemberSettings.SuppressSuggestedCandidatesEmails,
                EmailEmployerUpdate        = EmailCategory(employerUpdateCategory, settings),
                EmailCampaign              = EmailCategory(campaignCategory, settings),
            };

            return(View(model));
        }
Esempio n. 4
0
        public void UpdateCommunicationCategoryTest()
        {
            // Create campaign.

            Campaign campaign;
            Template template;

            CreateTestCampaign(1, out campaign, out template);
            Assert.IsNull(campaign.CommunicationCategoryId);

            // Update.

            campaign.CommunicationCategoryId = _settingsQuery.GetCategories(UserType.Member)[1].Id;
            _campaignsCommand.UpdateCampaign(campaign);

            // Get them.

            AssertCampaign(campaign, template);
        }
Esempio n. 5
0
        public void CommunicationCategoryTest()
        {
            // Create campaign.

            var campaign = new Campaign
            {
                Name      = string.Format(CampaignNameFormat, 0),
                CreatedBy = Guid.NewGuid(),
                CommunicationCategoryId = _settingsQuery.GetCategories(UserType.Member)[1].Id
            };

            _campaignsCommand.CreateCampaign(campaign);

            var template = new Template
            {
                Subject = string.Format(TemplateSubjectFormat, 0),
                Body    = string.Format(TemplateBodyFormat, 0)
            };

            _campaignsCommand.CreateTemplate(campaign.Id, template);

            AssertCampaign(campaign, template);
        }
Esempio n. 6
0
        public void TestDefaults()
        {
            // By default some settings may be set up for the user so remove those first.

            var index  = 0;
            var member = _memberAccountsCommand.CreateTestMember(++index);

            _settingsCommand.DeleteSettings(member.Id);

            LogIn(member);
            Get(_settingsUrl);

            // The user's settings should reflect the defaults for the categories.

            var categories = _settingsQuery.GetCategories(UserType.Member);

            AssertCategories(categories);
            AssertSettings(categories, c => c.Timing, c => c.DefaultFrequency, c => c.Name);

            // The user's settings should also reflect the settings for the user.

            var settings = _settingsQuery.GetSettings(member.Id);

            AssertCategorySettings(categories, settings);

            // Create a member with a changed regular category.

            member   = _memberAccountsCommand.CreateTestMember(++index);
            settings = ChangeCategorySettings((from c in categories where c.Timing == Timing.Periodic select c).First().Id, Frequency.Monthly, member.Id);

            LogOut();
            LogIn(member);
            Get(_settingsUrl);
            AssertCategories(categories);
            AssertCategorySettings(categories, settings);

            // Create a member with a changed notification category.

            member   = _memberAccountsCommand.CreateTestMember(++index);
            settings = ChangeCategorySettings((from c in categories where c.Timing == Timing.Notification select c).First().Id, Frequency.Never, member.Id);

            LogOut();
            LogIn(member);
            Get(_settingsUrl);
            AssertCategories(categories);
            AssertCategorySettings(categories, settings);

            // Create a member with changed categories.

            member = _memberAccountsCommand.CreateTestMember(++index);
            ChangeCategorySettings(categories.First(c => c.Timing == Timing.Periodic).Id, Frequency.Daily, member.Id);
            settings = ChangeCategorySettings((from c in categories where c.Timing == Timing.Notification select c).Last().Id, Frequency.Never, member.Id);

            LogOut();
            LogIn(member);
            Get(_settingsUrl);
            AssertCategories(categories);
            AssertCategorySettings(categories, settings);

            // Change it back.

            settings = ChangeCategorySettings((from c in categories where c.Timing == Timing.Notification select c).Last().Id, Frequency.Immediately, member.Id);

            LogOut();
            LogIn(member);
            Get(_settingsUrl);
            AssertCategories(categories);
            AssertCategorySettings(categories, settings);
        }
Esempio n. 7
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()
            }));
        }