Ejemplo n.º 1
0
        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecutePostProspectInquiryCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService    service = localContext.OrganizationService;
            ITracingService         trace   = localContext.TracingService;
            Entity prospectInquiryEntity    = (Entity)context.InputParameters["Target"];

            string message = context.MessageName;
            string error   = "";

            try
            {
                ProspectInquiryHandler prospectInquiryHandler = new ProspectInquiryHandler(service, trace);
                prospectInquiryHandler.SetCity(prospectInquiryEntity);
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(String.Concat("(Exception)\n", ex.Message, Environment.NewLine, ex.StackTrace, Environment.NewLine, error));
            }
        }
        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecutePreValidateProspectInquiryDelete(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService    service = localContext.OrganizationService;
            ITracingService         trace   = localContext.TracingService;
            var prospectInquiryId           = (EntityReference)context.InputParameters["Target"];

            try
            {
                EntityCollection prospectInquiryRecords = CommonHandler.RetrieveRecordsByOneValue("lead", "leadid", prospectInquiryId.Id, service,
                                                                                                  null, OrderType.Ascending, new[] { "leadid", "statecode" });

                if (prospectInquiryRecords != null && prospectInquiryRecords.Entities.Count > 0)
                {
                    ProspectInquiryHandler prospectInquiryHandler = new ProspectInquiryHandler(service, trace);
                    prospectInquiryHandler.RestrictProspectInquiryDelete(prospectInquiryRecords.Entities[0]);
                }
            }

            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(ex.Message);
            }
        }
        public void CreateOpportunity()
        {

            #region 1. Setup / Arrange
            var orgServiceMock = new Mock<IOrganizationService>();
            var orgService = orgServiceMock.Object;
            var orgTracingMock = new Mock<ITracingService>();
            var orgTracing = orgTracingMock.Object;

            #region ProspectInquiry EntityCollection
            var ProspectInquiryCollection = new EntityCollection
            {
                EntityName = "lead",
                Entities =
                {
                    new Entity
                    {
                        Id = Guid.NewGuid(),
                        LogicalName = "lead",
                        EntityState = EntityState.Changed,
                        Attributes = new AttributeCollection
                        {
                            {"gsc_qualified", true}
                        }
                    }
                }
            };
            #endregion

            #endregion

            #region 2. Call/Action
            var ProspectInquiryHandler = new ProspectInquiryHandler(orgService, orgTracing);
            Entity OpportunityEntity = ProspectInquiryHandler.CreateOpportunity(ProspectInquiryCollection.Entities[0]);
            #endregion

            #region 3. Verify
            Assert.AreEqual(ProspectInquiryCollection.Entities[0].Id, OpportunityEntity.GetAttributeValue<EntityReference>("originatinglead").Id);
            #endregion
        }
Ejemplo n.º 4
0
        public void CreateCorporateIndividual()
        {
            #region 1. Setup / Arrange
            var orgServiceMock = new Mock <IOrganizationService>();
            var orgService     = orgServiceMock.Object;
            var orgTracingMock = new Mock <ITracingService>();
            var orgTracing     = orgTracingMock.Object;

            var sampleGuid = new Guid("ccfa2910-fa16-4c77-9c73-a2e646a2fe44");

            #region Collection Entity
            var ContactCollection = new EntityCollection()
            {
                EntityName = "account",
                Entities   =
                {
                }
            };
            #endregion

            #region Prospect EntityCollection
            var ProspectCollection = new EntityCollection
            {
                EntityName = "gsc_sls_prospect",
                Entities   =
                {
                    new Entity
                    {
                        Id          = Guid.NewGuid(),
                        LogicalName = "gsc_sls_prospect",
                        EntityState = EntityState.Changed,
                        Attributes  = new AttributeCollection
                        {
                            { "gsc_customertype",       new OptionSetValue(100000001) },
                            { "gsc_firstname",          "Leslie"                      },
                            { "gsc_middlename",         "G"                           },
                            { "gsc_lastname",           "Baliguat"                    },
                            { "gsc_emailaddress",       "*****@*****.**"       },
                            { "gsc_mobileno",           "1"                           },
                            { "gsc_alternatecontactno", "2"                           },
                            { "gsc_fax",                "3"                           },
                            { "gsc_gender",             new OptionSetValue(1)         },
                            { "gsc_maritalstatus",      new OptionSetValue(1)         },
                            { "gsc_countryid",          new EntityReference("country", sampleGuid)},
                            { "gsc_provinceid",         new EntityReference("province", sampleGuid)},
                            { "gsc_cityid",             new EntityReference("city", sampleGuid)},
                            { "gsc_street",             "1"                           },
                            { "gsc_zipcode",            "1"                           },
                            { "gsc_dealerid",           new EntityReference("account", sampleGuid)},
                            { "gsc_branchid",           new EntityReference("account", sampleGuid)},
                            { "gsc_recordownerid",      new EntityReference("contact", sampleGuid)},
                            { "gsc_companyname",        "Star Magic"                  },
                            { "gsc_phone",              "2"                           },
                            { "gsc_website",            "www.starmagic.com"           },
                        }
                    }
                }
            };
            #endregion

            #region ProspectInquiry EntityCollection
            var ProspectInquiryCollection = new EntityCollection
            {
                EntityName = "lead",
                Entities   =
                {
                    new Entity
                    {
                        Id          = Guid.NewGuid(),
                        LogicalName = "lead",
                        EntityState = EntityState.Changed,
                        Attributes  = new AttributeCollection
                        {
                            { "gsc_qualified",   true                               },
                            { "gsc_prospectid",  new EntityReference(ProspectCollection.EntityName, ProspectCollection.Entities[0].Id)},
                            { "parentaccountid", null                               },
                            { "parentcontactid", null                               }
                        }
                    }
                }
            };
            #endregion

            orgServiceMock.Setup((service => service.RetrieveMultiple(
                                      It.Is <QueryExpression>(expression => expression.EntityName == ProspectCollection.EntityName)
                                      ))).Returns(ProspectCollection);

            orgServiceMock.Setup((service => service.RetrieveMultiple(
                                      It.Is <QueryExpression>(expression => expression.EntityName == ContactCollection.EntityName)
                                      ))).Returns(ContactCollection);

            orgServiceMock.Setup(service => service.Retrieve(
                                     It.IsAny <string>(),
                                     It.IsAny <Guid>(),
                                     It.IsAny <ColumnSet>())).Returns(ProspectInquiryCollection.Entities[0]);

            orgServiceMock.Setup((service => service.Update(It.Is <Entity>(entity => entity.LogicalName == ProspectInquiryCollection.Entities[0].LogicalName)))).Callback <Entity>(s => ProspectInquiryCollection.Entities[0] = s);


            #endregion

            #region 2. Call/Action
            var    ProspectInquiryHandler = new ProspectInquiryHandler(orgService, orgTracing);
            Entity ContactEntity          = ProspectInquiryHandler.CreateCustomer(ProspectInquiryCollection.Entities[0]);
            #endregion

            #region 3. Verify
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<OptionSetValue>("gsc_customertype").Value - 1, ContactEntity.GetAttributeValue<OptionSetValue>("gsc_customertype").Value);
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<String>("gsc_companyname"), ContactEntity.GetAttributeValue<String>("name"));
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<String>("gsc_phone"), ContactEntity.GetAttributeValue<String>("telephone1"));
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<String>("gsc_website"), ContactEntity.GetAttributeValue<String>("websiteurl"));
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<String>("gsc_fax"), ContactEntity.GetAttributeValue<String>("fax"));
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<EntityReference>("gsc_countryid").Id, ContactEntity.GetAttributeValue<EntityReference>("gsc_countryid").Id);
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<EntityReference>("gsc_provinceid").Id, ContactEntity.GetAttributeValue<EntityReference>("gsc_provinceid").Id);
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<EntityReference>("gsc_cityid").Id, ContactEntity.GetAttributeValue<EntityReference>("gsc_cityid").Id);
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<String>("gsc_street"), ContactEntity.GetAttributeValue<String>("address1_line1"));
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<String>("gsc_zipcode"), ContactEntity.GetAttributeValue<String>("address1_postalcode"));
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<EntityReference>("gsc_dealerid").Id, ContactEntity.GetAttributeValue<EntityReference>("gsc_dealerid").Id);
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<EntityReference>("gsc_branchid").Id, ContactEntity.GetAttributeValue<EntityReference>("gsc_branchid").Id);
            //Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue<EntityReference>("gsc_recordownerid").Id, ContactEntity.GetAttributeValue<EntityReference>("gsc_recordownerid").Id);
            //Assert.AreEqual(true, ContactEntity.GetAttributeValue<Boolean>("gsc_isaccount"));
            //Assert.AreEqual(true, ContactEntity.GetAttributeValue<Boolean>("gsc_ispotential"));
            //Assert.AreEqual(true, ContactEntity.GetAttributeValue<Boolean>("gsc_prospect"));
            Assert.AreEqual(true, ProspectInquiryCollection.Entities[0].GetAttributeValue <EntityReference>("parentcontactid") == null);
            Assert.AreEqual(false, ProspectInquiryCollection.Entities[0].GetAttributeValue <EntityReference>("parentaccountid") == null);
            #endregion
        }
Ejemplo n.º 5
0
        public void ConcatenateVehicleInfoWithNullValues()
        {
            #region 1. Setup / Arrange
            var orgServiceMock = new Mock <IOrganizationService>();
            var orgService     = orgServiceMock.Object;
            var orgTracingMock = new Mock <ITracingService>();
            var orgTracing     = orgTracingMock.Object;

            #region Vehicle Base Model Entity
            var VehicleBaseModelCollection = new EntityCollection()
            {
                EntityName = "gsc_iv_vehiclebasemodel",
                Entities   =
                {
                    new Entity
                    {
                        Id          = Guid.NewGuid(),
                        LogicalName = "gsc_iv_vehiclebasemodel",
                        Attributes  =
                        {
                            { "gsc_basemodelpn", "Strada" }
                        }
                    }
                }
            };
            #endregion

            #region ProspectInquiry EntityCollection
            var ProspectInquiryCollection = new EntityCollection
            {
                EntityName = "lead",
                Entities   =
                {
                    new Entity
                    {
                        Id          = Guid.NewGuid(),
                        LogicalName = "lead",
                        EntityState = EntityState.Changed,
                        Attributes  = new AttributeCollection
                        {
                            { "gsc_vehiclebasemodelid", new EntityReference() },
                            { "fullname",               ""                    },
                            { "topic",                  ""                    },
                        }
                    }
                }
            };
            #endregion

            orgServiceMock.Setup((service => service.RetrieveMultiple(
                                      It.Is <QueryExpression>(expression => expression.EntityName == VehicleBaseModelCollection.EntityName)
                                      ))).Returns(VehicleBaseModelCollection);

            #endregion

            #region 2. Call/Action

            var    ProspectInquiryHandler = new ProspectInquiryHandler(orgService, orgTracing);
            String Subject = ProspectInquiryHandler.ConcatenateVehicleInfo(ProspectInquiryCollection.Entities[0], "Create");

            #endregion

            #region 3. Verify
            var vehiclemodel = VehicleBaseModelCollection.Entities[0]["gsc_basemodelpn"];
            var fullname     = ProspectInquiryCollection.Entities[0]["fullname"];
            var topic        = fullname + " - " + vehiclemodel;
            Assert.AreEqual(topic, Subject);

            #endregion
        }
Ejemplo n.º 6
0
        public void ReplicateProspectInfoUnitTest()
        {
            #region 1. Setup / Arrange
            var orgServiceMock = new Mock <IOrganizationService>();
            var orgService     = orgServiceMock.Object;
            var orgTracingMock = new Mock <ITracingService>();
            var orgTracing     = orgTracingMock.Object;

            #region Prospect EntityCollection
            var ProspectCollection = new EntityCollection
            {
                EntityName = "gsc_sls_prospect",
                Entities   =
                {
                    new Entity
                    {
                        Id          = Guid.NewGuid(),
                        LogicalName = "gsc_sls_prospect",
                        EntityState = EntityState.Changed,
                        Attributes  = new AttributeCollection
                        {
                            { "gsc_firstname",    "Mark"               },
                            { "gsc_middlename",   ""                   },
                            { "gsc_lastname",     "Opaco"              },
                            { "gsc_mobileno",     "09123456789"        },
                            { "gsc_emailaddress", "*****@*****.**" },
                            { "gsc_street",       "Antipolo St."       },
                            { "gsc_cityid",       new EntityReference("gsc_syscity", Guid.NewGuid())
                                {
                                    Name = "Manila"
                                } },
                            { "gsc_provinceid",   new EntityReference("gsc_sysregion", Guid.NewGuid())
                                {
                                    Name = "Manila"
                                } },
                            { "gsc_countryid",    new EntityReference("gsc_syscountry", Guid.NewGuid())
                                {
                                    Name = "Philippines"
                                } },
                        }
                    }
                }
            };
            #endregion

            #region ProspectInquiry EntityCollection
            var ProspectInquiryCollection = new EntityCollection
            {
                EntityName = "Prospect Inquiry",
                Entities   =
                {
                    new Entity
                    {
                        Id          = Guid.NewGuid(),
                        LogicalName = "lead",
                        EntityState = EntityState.Created,
                        Attributes  = new AttributeCollection
                        {
                            { "firstname",                ""                                 },
                            { "middlename",               ""                                 },
                            { "lastname",                 ""                                 },
                            { "fullname",                 ""                                 },
                            { "mobilephone",              ""                                 },
                            { "emailaddress1",            ""                                 },
                            { "address1_line1",           ""                                 },
                            { "address1_city",            ""                                 },
                            { "address1_stateorprovince", ""                                 },
                            { "address1_country",         ""                                 },
                            { "gsc_prospectid",           new EntityReference("gsc_sls_prospect", ProspectCollection.Entities[0].Id)},
                        }
                    }
                }
            };
            #endregion

            orgServiceMock.Setup((service => service.RetrieveMultiple(
                                      It.Is <QueryExpression>(expression => expression.EntityName == ProspectCollection.EntityName)
                                      ))).Returns(ProspectCollection);

            #endregion

            #region 2. Call/Action

            var    ProspectInquiryHandler = new ProspectInquiryHandler(orgService, orgTracing);
            Entity prospectInquiry        = ProspectInquiryHandler.ReplicateProspectInfo(ProspectInquiryCollection.Entities[0]);
            #endregion

            #region 3. Verify
            var fullname = ProspectCollection.Entities[0]["gsc_firstname"] + " " + ProspectCollection.Entities[0]["gsc_lastname"];
            Assert.AreEqual(ProspectCollection.Entities[0]["gsc_firstname"], prospectInquiry["firstname"]);
            Assert.AreEqual(ProspectCollection.Entities[0]["gsc_middlename"], prospectInquiry["middlename"]);
            Assert.AreEqual(ProspectCollection.Entities[0]["gsc_lastname"], prospectInquiry["lastname"]);
            Assert.AreEqual(fullname, prospectInquiry["fullname"]);
            Assert.AreEqual(ProspectCollection.Entities[0]["gsc_mobileno"], prospectInquiry["mobilephone"]);
            Assert.AreEqual(ProspectCollection.Entities[0]["gsc_emailaddress"], prospectInquiry["emailaddress1"]);
            Assert.AreEqual(ProspectCollection.Entities[0]["gsc_street"], prospectInquiry["address1_line1"]);
            Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue <EntityReference>("gsc_cityid").Name, prospectInquiry["address1_city"]);
            Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue <EntityReference>("gsc_provinceid").Name, prospectInquiry["address1_stateorprovince"]);
            Assert.AreEqual(ProspectCollection.Entities[0].GetAttributeValue <EntityReference>("gsc_countryid").Name, prospectInquiry["address1_country"]);
            #endregion
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecutePostProspectInquiryUpdate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService    service = localContext.OrganizationService;
            ITracingService         trace   = localContext.TracingService;

            Entity preImageEntity  = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.preImageAlias)) ? context.PreEntityImages[this.preImageAlias] : null;
            Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;


            if (!(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity))
            {
                return;
            }

            if (postImageEntity.LogicalName != "lead")
            {
                return;
            }

            string message = context.MessageName;

            if (context.Mode == 0) //synchronous plugin
            {
                try
                {
                    ProspectInquiryHandler prospectInquiryHandler = new ProspectInquiryHandler(service, trace);

                    var preImageBaseModelId = preImageEntity.Contains("gsc_vehiclebasemodelid")
                         ? preImageEntity.GetAttributeValue <EntityReference>("gsc_vehiclebasemodelid").Id
                         : Guid.Empty;

                    var preImageDisqualified = preImageEntity.GetAttributeValue <Boolean>("gsc_disqualified");

                    var preImageDisqualifiedStatusReason = preImageEntity.Contains("gsc_disqualifiedstatusreason")
                        ? preImageEntity.GetAttributeValue <Int32>("gsc_disqualifiedstatusreason")
                        : 0;

                    var preImageQualified = preImageEntity.GetAttributeValue <Boolean>("gsc_qualified");

                    var preImageCityName = preImageEntity.Contains("gsc_cityname") ? preImageEntity.GetAttributeValue <string>("gsc_cityname")
                        : String.Empty;

                    var preImageCityIdName = preImageEntity.Contains("gsc_cityid") ? preImageEntity.GetAttributeValue <EntityReference>("gsc_cityid").Name
                        : String.Empty;



                    var postImageBaseModelId = postImageEntity.Contains("gsc_vehiclebasemodelid")
                        ? postImageEntity.GetAttributeValue <EntityReference>("gsc_vehiclebasemodelid").Id
                        : Guid.Empty;

                    var postImageDisqualified = postImageEntity.GetAttributeValue <Boolean>("gsc_disqualified");

                    var postImageDisqualifiedStatusReason = postImageEntity.Contains("gsc_disqualifiedstatusreason")
                        ? postImageEntity.GetAttributeValue <Int32>("gsc_disqualifiedstatusreason")
                        : 0;

                    var postImageQualified = postImageEntity.GetAttributeValue <Boolean>("gsc_qualified");

                    var postImageCityName = postImageEntity.Contains("gsc_cityname") ? postImageEntity.GetAttributeValue <string>("gsc_cityname")
                        : String.Empty;

                    var postImageCityIdName = postImageEntity.Contains("gsc_cityid") ? postImageEntity.GetAttributeValue <EntityReference>("gsc_cityid").Name
                        : String.Empty;

                    //execute the method when Base Model Id was changed
                    if (preImageBaseModelId != postImageBaseModelId)
                    {
                        prospectInquiryHandler.ConcatenateVehicleInfo(postImageEntity, message);
                    }

                    //Call DisqualifyProspectInquiry method on Disqualified and Disqualified Status Reason change
                    if (preImageDisqualified != postImageDisqualified && preImageDisqualifiedStatusReason != postImageDisqualifiedStatusReason)
                    {
                        prospectInquiryHandler.DisqualifyProspectInquiry(postImageEntity);
                    }
                    //Call QualifyProsctInquiry
                    if (preImageQualified != postImageQualified)
                    {
                        prospectInquiryHandler.CreateCustomer(postImageEntity);
                        prospectInquiryHandler.CreateOpportunity(postImageEntity);
                        prospectInquiryHandler.QualifyProspectInquiry(postImageEntity);
                    }

                    if (postImageCityName != postImageCityIdName && postImageCityName != String.Empty && preImageCityIdName == postImageCityIdName)
                    {
                        prospectInquiryHandler.SetCity(postImageEntity);
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException(String.Concat(ex.Message));
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecutePreProspectInquiryCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService    service = localContext.OrganizationService;
            ITracingService         trace   = localContext.TracingService;
            Entity prospectInquiry          = (Entity)context.InputParameters["Target"];

            if (!(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity))
            {
                return;
            }

            if (prospectInquiry.LogicalName != "lead")
            {
                return;
            }

            string message = context.MessageName;

            if (context.Mode == 0) //synchronous plugin
            {
                try
                {
                    ProspectInquiryHandler prospectInquiryHandler = new ProspectInquiryHandler(service, trace);
                    prospectInquiryHandler.GetDefaultTax();
                    prospectInquiryHandler.ReplicateProspectInfo(prospectInquiry);
                    prospectInquiryHandler.ConcatenateVehicleInfo(prospectInquiry, message);
                    //set Portal User Id
                    prospectInquiry["gsc_portaluserid"] = prospectInquiry.GetAttributeValue <EntityReference>("gsc_recordownerid") != null
                        ? prospectInquiry.GetAttributeValue <EntityReference>("gsc_recordownerid").Id.ToString()
                        : String.Empty;

                    //Set Name for corporate
                    var prospectType = prospectInquiry.Contains("gsc_prospecttype") ? prospectInquiry.GetAttributeValue <OptionSetValue>("gsc_prospecttype").Value : 0;
                    if (prospectType != 100000000)
                    {
                        prospectInquiry["gsc_prospectname"] = prospectInquiry.GetAttributeValue <String>("companyname") != null
                        ? prospectInquiry.GetAttributeValue <String>("companyname")
                        : String.Empty;
                    }
                    else
                    {
                        prospectInquiry["gsc_prospectname"] = prospectInquiry.GetAttributeValue <String>("fullname") != null
                        ? prospectInquiry.GetAttributeValue <String>("fullname")
                        : String.Empty;
                    }

                    if (prospectInquiryHandler.CheckForExistingRecords(prospectInquiry) == true)
                    {
                        throw new InvalidPluginExecutionException("This record has been identified as a fraud account. Please ask the customer to provide further information.");
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("This record has been identified as a fraud account. Please ask the customer to provide further information."))
                    {
                        throw new InvalidPluginExecutionException("This record has been identified as a fraud account. Please ask the customer to provide further information.");
                    }
                    else
                    {
                        throw new InvalidPluginExecutionException(ex.Message);
                    }
                }
            }
        }