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));
        }
        private MemberAccess AccessMember(ChannelApp app, IEmployer employer, ProfessionalView view, MemberAccessReason reason)
        {
            // An anonymous employer means insufficient credits.

            if (employer == null)
            {
                throw new InsufficientCreditsException {
                          Available = 0, Required = 1
                }
            }
            ;

            // Make sure the details are visible.

            CheckVisibility(view, reason);

            // Check against limits.

            CheckAccessLimit(employer.Id, view.Id, reason);

            // Exercise the credit.

            var exercisedCreditId = _employerCreditsCommand.ExerciseContactCredit(employer, view);

            // Record the access.

            return(CreateMemberAccess(app, employer.Id, view.Id, reason, exercisedCreditId));
        }
        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);
            }
        }
        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));
            }
        }
        private MemberAccess CreateMemberAccess(ChannelApp app, Guid employerId, Guid memberId, MemberAccessReason reason, Guid?exercisedCreditId)
        {
            var access = new MemberAccess
            {
                Reason            = reason,
                EmployerId        = employerId,
                MemberId          = memberId,
                ExercisedCreditId = exercisedCreditId,
                ChannelId         = app.ChannelId,
                AppId             = app.Id,
            };

            access.Prepare();
            access.Validate();
            _repository.CreateMemberAccess(access);
            return(access);
        }
        void IEmployerMemberContactsCommand.ContactMember(ChannelApp app, IEmployer employer, ProfessionalView view, ContactMemberMessage messageTemplate)
        {
            var cleaner        = new MemberMessageCleaner();
            var cleanedBody    = cleaner.CleanBody(messageTemplate.Body);
            var cleanedSubject = cleaner.CleanSubject(messageTemplate.Subject);

            // Messages are being sent so exercise a credit.

            var access = _employerMemberViewsCommand.AccessMember(app, employer, view, MemberAccessReason.MessageSent);

            // Save the message.

            if (access != null)
            {
                var handlers         = MessageCreated;
                var representativeId = _memberContactsQuery.GetRepresentativeContact(view.Id);
                ContactMember(messageTemplate, employer, view, cleanedSubject, cleanedBody, representativeId, access, handlers);
            }
        }
        private void CreateMemberViewing(ChannelApp app, IHasId <Guid> employer, IHasId <Guid> member, Application application)
        {
            if (member == null)
            {
                return;
            }

            var viewing = new MemberViewing
            {
                EmployerId = employer == null ? (Guid?)null : employer.Id,
                MemberId   = member.Id,
                JobAdId    = application == null ? (Guid?)null : application.PositionId,
                ChannelId  = app.ChannelId,
                AppId      = app.Id,
            };

            viewing.Prepare();
            viewing.Validate();
            _repository.CreateMemberViewing(viewing);
        }
        private IList <MemberAccess> CreateMemberAccesses(ChannelApp app, Guid employerId, IEnumerable <Guid> memberIds, MemberAccessReason reason, IDictionary <Guid, Guid?> exercisedCreditIds)
        {
            var accesses = new List <MemberAccess>();

            foreach (var memberId in memberIds)
            {
                var access = new MemberAccess
                {
                    Reason            = reason,
                    EmployerId        = employerId,
                    MemberId          = memberId,
                    ExercisedCreditId = exercisedCreditIds[memberId],
                    ChannelId         = app.ChannelId,
                    AppId             = app.Id,
                };
                access.Prepare();
                access.Validate();
                accesses.Add(access);
            }

            _repository.CreateMemberAccesses(accesses);
            return(accesses);
        }
Exemple #9
0
 /// <summary>
 /// 提交表单
 /// </summary>
 /// <param name="readTaskEntity"></param>
 /// <param name="keyValue"></param>
 public void SubmitForm(ReadTaskEntity readTaskEntity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         _service.Update(readTaskEntity);
     }
     else
     {
         var meter = _meterApp.GetFormByMeterCode(readTaskEntity.F_MeterCode);
         if (meter != null)
         {
             var channel = new ChannelApp().GetFormByArchiveId(meter.F_Id);
             if (channel != null)
             {
                 readTaskEntity.F_Param       = channel.F_Id;
                 readTaskEntity.F_ChannelType = (int)ChannelTypeEnum.Mbus;
             }
         }
         readTaskEntity.F_Id          = Common.GuId();
         readTaskEntity.F_CreatorTime = DateTime.Now;
         _service.Insert(readTaskEntity);
     }
 }
 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));
 }
 MemberAccess IEmployerMemberViewsCommand.AccessMember(ChannelApp app, IEmployer employer, ProfessionalView view, MemberAccessReason reason)
 {
     return(AccessMember(app, employer, view, reason));
 }
Exemple #13
0
 public ChannelContext(ChannelApp app)
 {
     _app = app;
 }
 void IEmployerMemberViewsCommand.ViewMember(ChannelApp app, IEmployer employer, IMember member)
 {
     CreateMemberViewing(app, employer, member, null);
 }
 void IEmployerMemberContactsCommand.CheckCanContactMember(ChannelApp app, IEmployer employer, ProfessionalView view)
 {
     _employerMemberViewsCommand.CheckCanAccessMember(app, employer, view, MemberAccessReason.MessageSent);
 }
 void IEmployerMemberViewsCommand.ViewMember(ChannelApp app, IEmployer employer, IMember member, InternalApplication application)
 {
     CreateMemberViewing(app, employer, member, application);
 }
Exemple #17
0
 private static void AssertChannelApp(Guid channelId, string name, ChannelApp channelApp)
 {
     Assert.IsNotNull(channelApp);
     Assert.AreEqual(channelId, channelApp.ChannelId);
     Assert.AreEqual(name, channelApp.Name);
 }