public void TestChannelApp() { var employer = CreateEmployer(1); var member1 = CreateMember(employer, 1); var member2 = CreateMember(employer, 2); var member3 = CreateMember(employer, 3); var member4 = CreateMember(employer, 4); var channelApp1 = _channelsQuery.GetChannelApp(_channelsQuery.GetChannel("Web").Id, "Web"); var channelApp2 = _channelsQuery.GetChannelApp(_channelsQuery.GetChannel("API").Id, "iOS"); _employerMemberViewsCommand.CheckCanAccessMember(channelApp1, employer, member1, MemberAccessReason.Unlock); _employerMemberViewsCommand.AccessMember(channelApp1, employer, member1, MemberAccessReason.Unlock); _employerMemberViewsCommand.CheckCanAccessMember(channelApp2, employer, member2, MemberAccessReason.Unlock); _employerMemberViewsCommand.AccessMember(channelApp2, employer, member2, MemberAccessReason.Unlock); var views = new ProfessionalViews { member1, member3 }; _employerMemberViewsCommand.AccessMembers(channelApp2, employer, views, MemberAccessReason.Unlock); _employerMemberViewsCommand.CheckCanAccessMember(channelApp1, employer, member4, MemberAccessReason.Unlock); _employerMemberViewsCommand.AccessMember(channelApp1, employer, member4, MemberAccessReason.Unlock); AssertMemberAccesses(employer.Id, member1.Id, channelApp1, channelApp2); AssertMemberAccesses(employer.Id, member2.Id, channelApp2); AssertMemberAccesses(employer.Id, member3.Id, channelApp2); }
private void CheckCanAccessMembers(IEmployer employer, ProfessionalViews views, MemberAccessReason reason) { switch (views.Count()) { case 0: break; case 1: CheckCanAccessMember(employer, views.First(), reason); break; default: CheckCanAccessBulkMembers(employer, views, reason); break; } }
void IEmployerMemberContactsCommand.RejectMembers(IEmployer employer, ProfessionalViews views, RejectionMemberMessage messageTemplate) { var cleaner = new MemberMessageCleaner(); var cleanedBody = cleaner.CleanBody(messageTemplate.Body); var cleanedSubject = cleaner.CleanSubject(messageTemplate.Subject); // Get the member and the representative if there is one. var representativeIds = _memberContactsQuery.GetRepresentativeContacts(from m in views select m.Id); // Iterate through them all exercising credits when needed. var handlers = MessageCreated; foreach (var view in views) { var representativeId = representativeIds[view.Id]; ContactMember(messageTemplate, employer, view, cleanedSubject, cleanedBody, representativeId, null, handlers); } }
private void CheckCanAccessBulkMembers(IEmployer employer, ProfessionalViews views, MemberAccessReason reason) { if (employer == null) { throw new InsufficientCreditsException { Available = 0, Required = views.Count() } } ; // Make sure the details are visible. CheckVisibility(views, reason); // Check against limits. CheckAccessLimit(employer.Id, from v in views select v.Id, reason); // Check the credits. _employerCreditsCommand.CheckCanExerciseContactCredits(employer, views); }
void IEmployerMemberContactsCommand.ContactMembers(ChannelApp app, IEmployer employer, ProfessionalViews views, ContactMemberMessage messageTemplate) { var cleaner = new MemberMessageCleaner(); var cleanedBody = cleaner.CleanBody(messageTemplate.Body); var cleanedSubject = cleaner.CleanSubject(messageTemplate.Subject); // Try to access all the members. var accesses = _employerMemberViewsCommand.AccessMembers(app, employer, views, MemberAccessReason.MessageSent); // Get the member and the representative if there is one. var representativeIds = _memberContactsQuery.GetRepresentativeContacts(from m in views select m.Id); // Iterate through them all exercising credits when needed. var handlers = MessageCreated; foreach (var view in views) { var viewId = view.Id; var representativeId = representativeIds[view.Id]; var access = (from a in accesses where a.MemberId == viewId select a).SingleOrDefault(); ContactMember(messageTemplate, employer, view, cleanedSubject, cleanedBody, representativeId, access, handlers); } }
void IEmployerMemberContactsCommand.CheckCanContactMembers(ChannelApp app, IEmployer employer, ProfessionalViews views) { _employerMemberViewsCommand.CheckCanAccessMembers(app, employer, views, MemberAccessReason.MessageSent); }
private IList <MemberAccess> AccessMembers(ChannelApp app, IEmployer employer, ProfessionalViews views, MemberAccessReason reason) { switch (views.Count()) { case 0: return(new List <MemberAccess>()); case 1: return(new List <MemberAccess> { AccessMember(app, employer, views.First(), reason) }); default: return(AccessBulkMembers(app, employer, views, reason)); } }
void IEmployerMemberViewsCommand.CheckCanAccessMembers(ChannelApp app, IEmployer employer, ProfessionalViews views, MemberAccessReason reason) { CheckCanAccessMembers(employer, views, reason); }
IList <MemberAccess> IEmployerMemberViewsCommand.AccessMembers(ChannelApp app, IEmployer employer, ProfessionalViews views, MemberAccessReason reason) { return(AccessMembers(app, employer, views, reason)); }
private IList <MemberAccess> AccessBulkMembers(ChannelApp app, IEmployer employer, ProfessionalViews views, MemberAccessReason reason) { if (employer == null) { throw new InsufficientCreditsException { Available = 0, Required = views.Count() } } ; // Make sure the details are visible. CheckVisibility(views, reason); // Check against limits. CheckAccessLimit(employer.Id, from v in views select v.Id, reason); // Exercise the credits. var exercisedCreditIds = _employerCreditsCommand.ExerciseContactCredits(employer, views); // Record the accesses. return(CreateMemberAccesses(app, employer.Id, from v in views select v.Id, reason, exercisedCreditIds)); }