コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context">Local plug-in context.</param>
        protected void UpdateRelatedRiskIdentifier(LocalPluginContext context)
        {
            var postImage = context.PostImage;
            var target    = context.PluginExecutionContext.InputParameters["Target"] as Entity;

            var insuredRisk = new InsuredRisk(context.OrganizationService, context.TracingService, postImage);

            var riskClass = insuredRisk.RiskClass;

            if (riskClass == null)
            {
                throw new InvalidPluginExecutionException("Risk class is not specified for insured risk.");
            }

            if (string.IsNullOrEmpty(riskClass.InsuredRiskLookup))
            {
                throw new InvalidPluginExecutionException("Risk class configuration error - risk lookup field name is empty.");
            }

            // we update risk identifier of risk entity only if it was just attached to the insured risk.
            if (!target.Contains(riskClass.InsuredRiskLookup))
            {
                return;
            }

            var policyVersion = insuredRisk.PolicyVersion;

            if (policyVersion == null)
            {
                throw new InvalidPluginExecutionException("Policy version is not selected for this insured risk.");
            }

            var policyFolder = policyVersion.PolicyFolder;
            //if (policyFolder == null)
            //    throw new InvalidPluginExecutionException("Policy is not selected for policy version.");

            var riskEntityRef = insuredRisk.RiskEntityRef;

            if (riskEntityRef == null)
            {
                return;
            }

            var riskEntity = context.OrganizationService.Retrieve(riskEntityRef);

            var identifier = GetRiskIdentifierString(context.OrganizationService, policyFolder == null ? null : policyFolder.Entity, insuredRisk.Entity, riskEntity, riskClass.Identifiers);

            if (string.IsNullOrEmpty(identifier))
            {
                return;
            }

            // if identifier is different to current name, update risk entity
            if (identifier != riskEntity.GetAttributeValue <string>("new_name"))
            {
                var updatedRiskEntity = new Entity(riskEntity.LogicalName);
                updatedRiskEntity["new_name"] = identifier;
                updatedRiskEntity.Id          = riskEntity.Id;

                context.OrganizationService.Update(updatedRiskEntity);
            }

            // always update insured risk, because it might have been initially created without risk entity identifier
            var insuredRiskName    = "{0} - {1}".FormatWith(policyVersion.PolicyVersionNumber, identifier);
            var updatedInsuredRisk = new Entity("new_insuredrisk");

            updatedInsuredRisk["new_name"] = insuredRiskName.LimitLength(250);
            updatedInsuredRisk.Id          = target.Id;

            context.OrganizationService.Update(updatedInsuredRisk);
        }
コード例 #2
0
        private void CreateInsuredCoversForInsuredRisk(LocalPluginContext context)
        {
            var target           = context.PluginExecutionContext.InputParameters["Target"] as Entity;
            var insuredRisk      = new InsuredRisk(context.OrganizationService, context.TracingService, target);
            var excess           = insuredRisk.RiskExcess;
            var linitOfIndemnity = insuredRisk.RiskLOI;

            var retrievedRisk = insuredRisk.Risk;

            if (retrievedRisk != null)
            {
                var riskExcess = retrievedRisk.RiskDefaultExcess;
                var riskLOI    = retrievedRisk.RiskDefaultLOI;

                Entity insuredRiskToUpdate = new Entity(insuredRisk.LogicalName);
                insuredRiskToUpdate.Id = insuredRisk.Id;
                if (riskExcess == null)
                {
                    insuredRiskToUpdate["new_excess"] = riskExcess;
                }
                if (riskLOI == null)
                {
                    insuredRiskToUpdate["new_limitofindemnity"] = riskLOI;
                }

                context.OrganizationService.Update(insuredRiskToUpdate);
            }

            if (!CheckIfCreatingInsuredRisks(insuredRisk.PolicyVersion))
            {
                return;
            }

            //if (!CheckIfCreatingInsuredRisks(insuredRisk.PolicyVersion))
            //    return;

            if (!CheckIfCreatingInsuredRisks(insuredRisk.PolicyVersion))
            {
                return;
            }

            var risk = insuredRisk.Risk;

            if (risk == null)
            {
                throw new InvalidPluginExecutionException("Insured risk requires a risk ID.");
            }

            foreach (var c in risk.Covers)
            {
                if (!c.Mandatory)
                {
                    continue;
                }

                var newInsCover = new Entity("new_insuredcover");
                newInsCover["new_policyid"]      = insuredRisk.PolicyVersionRef;
                newInsCover["new_insuredriskid"] = insuredRisk.EntityReference;
                newInsCover["new_coverid"]       = c.EntityReference;
                context.OrganizationService.Create(newInsCover);
            }
        }
コード例 #3
0
        /// <summary>
        /// Sets new_name of an insured risk based on parent policy version number and new_name of risk entity.
        /// Since new_name of risk entity is risk identifier, which might depend on insured risk and its policy,
        /// it gets updated as well.
        /// </summary>
        /// <param name="context">Local plug-in context.</param>
        protected void AutoNameInsuredRiskOnCreate(LocalPluginContext context)
        {
            var target      = context.PluginExecutionContext.InputParameters["Target"] as Entity;
            var insuredRisk = new InsuredRisk(context.OrganizationService, context.TracingService, target);

            var policyVersion = insuredRisk.PolicyVersion;

            if (policyVersion == null)
            {
                throw new InvalidPluginExecutionException("Policy version is not selected for this insured risk.");
            }

            var riskClass = insuredRisk.RiskClass;

            if (riskClass == null)
            {
                throw new InvalidPluginExecutionException("Risk class is not specified for insured risk.");
            }

            if (string.IsNullOrEmpty(riskClass.InsuredRiskLookup))
            {
                throw new InvalidPluginExecutionException("Risk class configuration error - risk lookup field name is empty.");
            }

            string riskName = null;

            // if risk entity (e.g.) is included in create request, its risk identifier might need to get updated
            var riskIdentifiers = riskClass.Identifiers;

            if (!riskIdentifiers.Any())
            {
                var riskSubClass = insuredRisk.RiskSubClass;
                if (riskSubClass != null)
                {
                    riskName = riskSubClass.Entity.GetAttributeValue <string>("new_name");
                }
            }
            else if (target.Contains(riskClass.InsuredRiskLookup))
            {
                var riskEntityRef = target.GetAttributeValue <EntityReference>(riskClass.InsuredRiskLookup);
                var riskEntity    = context.OrganizationService.Retrieve(riskEntityRef);

                var policyFolder = policyVersion.PolicyFolder;
                //if (policyFolder == null)
                //    throw new InvalidPluginExecutionException("Policy is not selected for policy version.");

                riskName = riskEntity.GetAttributeValue <string>("new_name");

                if (riskIdentifiers.Any())
                {
                    var identifier = GetRiskIdentifierString(context.OrganizationService, policyFolder == null ? null : policyFolder.Entity, insuredRisk.Entity, riskEntity, riskIdentifiers);
                    if (identifier != riskEntity.GetAttributeValue <string>("new_name"))
                    {
                        var updatedRiskEntity = new Entity(riskEntity.LogicalName);
                        updatedRiskEntity["new_name"] = identifier;
                        updatedRiskEntity.Id          = riskEntity.Id;

                        context.OrganizationService.Update(updatedRiskEntity);
                    }

                    riskName = identifier;
                }
            }

            var name = "{0} - {1}".FormatWith(policyVersion.PolicyVersionNumber, riskName);

            target["new_name"] = name.LimitLength(250);
        }