Пример #1
0
        public void AddInterviewToInterviewProcess(bru_interview_process interviewProcess)
        {
            _tracer.Trace("Start AddInterviewToInterviewProcess");

            var candidate = (from c in _xrmContext.ContactSet
                             where c.Id == interviewProcess.bru_candidate.Id
                             select c).FirstOrDefault();

            var candidateName = (candidate != null) ? candidate.FullName : Guid.NewGuid().ToString();


            var roles = (from c in _xrmContext.bru_jobroleSet
                         where c.bru_jobroleId == interviewProcess.bru_JobRole.Id
                         select c).FirstOrDefault();

            if (roles != null)
            {
                //create personal Interview
                if (roles.bru_PersonalInterviewType.Value == bru_personalinterviewtype.Developer)
                {
                    var personalinterview = new bru_personalinterview();
                    personalinterview.bru_name = candidateName + " - " + "Personal Interview Interview";
                    var personalinterviewID = _service.Create(personalinterview);
                    var relationship        = new Relationship("bru_bru_interview_process_bru_personalintervi");
                    var accountReferences   = new EntityReferenceCollection();

                    accountReferences.Add(interviewProcess.ToEntityReference());

                    _service.Associate(bru_personalinterview.EntityLogicalName, personalinterviewID, relationship, accountReferences);
                }

                //bru_bru_interview_process_bru_technicalinterv
                //create personal Interview
                if (roles.bru_TechnicalInterviewtype.Value == bru_technicalinterviewtype.Dynamics365Developer)
                {
                    var technicalinterview = new bru_technicalinterview();
                    technicalinterview.bru_name = candidateName + " - " + "Technical Interview";

                    var technicalInterviewID      = _service.Create(technicalinterview);
                    var relationship              = new Relationship("bru_bru_interview_process_bru_technicalinterv");
                    var entityReferenceCollection = new EntityReferenceCollection();
                    entityReferenceCollection.Add(interviewProcess.ToEntityReference());
                    _service.Associate(bru_technicalinterview.EntityLogicalName, technicalInterviewID, relationship, entityReferenceCollection);
                }
            }
            else
            {
                throw new InvalidPluginExecutionException("This user has NOT applied already");
            }
        }
Пример #2
0
        protected override void ExecuteCrmPlugin(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException(nameof(localContext));
            }
            IPluginExecutionContext context = localContext.PluginExecutionContext;

            const string target = PluginConstants.Target;

            if (!context.InputParameters.Contains(target) || !(context.InputParameters[target] is Entity))
            {
                return;
            }

            Entity entity = (Entity)context.InputParameters[target];

            bru_interview_process interview_process = entity.ToEntity <bru_interview_process>();

            if (!string.Equals(interview_process.LogicalName, bru_interview_process.EntityLogicalName, StringComparison.CurrentCultureIgnoreCase))
            {
                return;
            }
            if (!string.Equals(context.MessageName, PluginConstants.Create, StringComparison.CurrentCultureIgnoreCase))
            {
                return;
            }

            try
            {
                using (XrmSvc xrmContext = new XrmSvc(localContext.OrganizationService))
                {
                    var presenter = new InterviewProcessPresenter(xrmContext, localContext.OrganizationService, localContext.TracingService);
                    presenter.AddInterviewToInterviewProcess(interview_process);
                }
            }
            catch (Exception exception)
            {
                string errorMessage = exception.InnerException != null ? $"{exception.Message} | {exception.InnerException.Message}" : exception.Message;
                throw new InvalidPluginExecutionException($"An error has occurred while executing the 'pre-operation contact create' plug-in. The exception thrown was: {errorMessage}");
            }
        }