/// <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 ExecutePreContactCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)localContext.PluginExecutionContext;

            if (context.InputParameters.Contains("Target") &&
            context.InputParameters["Target"] is Entity)
            {

                //Organization Service
                IOrganizationService service = localContext.OrganizationService;

                //Tracing Service
                ITracingService trace = (ITracingService)localContext.TracingService;

                //Get the target entity
                Entity entity = (Entity)context.InputParameters["Target"];
                try
                {
                    //if (entity.Attributes.Contains("firstname"))
                    //{
                    //    entity.Attributes["jobtitle"] = "testing swsw";
                    //}

                    if (entity.Attributes.Contains("mobilephone"))
                    {

                        string message = "New contact added in system  for " + entity.Attributes["firstname"] + " " + entity.Attributes["lastname"];
                        SmsSender smsSender = new SmsSender();
                        string response = smsSender.SendSMS(entity.Attributes["mobilephone"].ToString(), "919460264151", "5b2a23d7", "59d9fa03",
                        Uri.EscapeUriString(message));

                  //      string fetchxmluser = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                  //          "<entity name='systemuser'>" +
                  //          "<attribute name='fullname' />" +
                  // "<attribute name='businessunitid' />" +
                  //"<attribute name='title' /> " +
                  //"<attribute name='address1_telephone1'/>" +
                  //"<attribute name='positionid' /> " +
                  //"<attribute name='systemuserid' /> " +
                  //"<attribute name='mobilephone' />" +
                  //"<attribute name='parentsystemuserid' />" +
                  //"<attribute name='firstname' />" +
                  //"<order attribute='fullname' descending= 'false' />" +
                  //"</entity>" +
                  // "</fetch>";


                        //EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetchxmluser));
                        //if (result.Entities.Count > 1)
                        //{

                        //    throw new InvalidPluginExecutionException(string.Format("Contract created by  : {0} and total user {1}", entity.Attributes["createdby"], result.Entities.Count));
                        //}

                        //if (entity.Attributes["mobilephone"].ToString() != "9999")
                        //{

                        //    throw new InvalidPluginExecutionException(string.Format("An error occured in PreContactCreate plugin: {0}", "invalid no"));
                        //}
                    }

                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException(string.Format("An error occured in PreContactCreate plugin: {0} {1} {2}", ex.ToString(), ex.InnerException, ex.StackTrace));
                }
            }
        }
        /// <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 ExecutePreContactCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)localContext.PluginExecutionContext;

            if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity)
            {
                //Organization Service
                IOrganizationService service = localContext.OrganizationService;

                //Tracing Service
                ITracingService trace = (ITracingService)localContext.TracingService;

                //Get the target entity
                Entity entity = (Entity)context.InputParameters["Target"];
                try
                {
                    //if (entity.Attributes.Contains("firstname"))
                    //{
                    //    entity.Attributes["jobtitle"] = "testing swsw";
                    //}

                    if (entity.Attributes.Contains("mobilephone"))
                    {
                        string    message   = "New contact added in system  for " + entity.Attributes["firstname"] + " " + entity.Attributes["lastname"];
                        SmsSender smsSender = new SmsSender();
                        string    response  = smsSender.SendSMS(entity.Attributes["mobilephone"].ToString(), "919460264151", "5b2a23d7", "59d9fa03",
                                                                Uri.EscapeUriString(message));

                        //      string fetchxmluser = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                        //          "<entity name='systemuser'>" +
                        //          "<attribute name='fullname' />" +
                        // "<attribute name='businessunitid' />" +
                        //"<attribute name='title' /> " +
                        //"<attribute name='address1_telephone1'/>" +
                        //"<attribute name='positionid' /> " +
                        //"<attribute name='systemuserid' /> " +
                        //"<attribute name='mobilephone' />" +
                        //"<attribute name='parentsystemuserid' />" +
                        //"<attribute name='firstname' />" +
                        //"<order attribute='fullname' descending= 'false' />" +
                        //"</entity>" +
                        // "</fetch>";


                        //EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetchxmluser));
                        //if (result.Entities.Count > 1)
                        //{

                        //    throw new InvalidPluginExecutionException(string.Format("Contract created by  : {0} and total user {1}", entity.Attributes["createdby"], result.Entities.Count));
                        //}

                        //if (entity.Attributes["mobilephone"].ToString() != "9999")
                        //{

                        //    throw new InvalidPluginExecutionException(string.Format("An error occured in PreContactCreate plugin: {0}", "invalid no"));
                        //}
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException(string.Format("An error occured in PreContactCreate plugin: {0} {1} {2}", ex.ToString(), ex.InnerException, ex.StackTrace));
                }
            }
        }