private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, LocalPluginContext localContext, IOrganizationService service, IPluginExecutionContext context)
        {
            localContext.TracingService.Trace("---------Send the Record to Azure---------");
            string messageName = context.MessageName;
            string text        = "Response";
            string text2       = Utilities.GetAzureWebAPIURL(service, context);

            localContext.TracingService.Trace("Got API URL: " + text2);
            if (text2 != string.Empty)
            {
                localContext.TracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord["msnfp_responseid"].ToString());
                MSNFP_Response mSNFP_Response = new MSNFP_Response();
                mSNFP_Response.ResponseId = (Guid)queriedEntityRecord["msnfp_responseid"];
                if (queriedEntityRecord.Contains("msnfp_transactionid") && queriedEntityRecord["msnfp_transactionid"] != null)
                {
                    mSNFP_Response.TransactionId = ((EntityReference)queriedEntityRecord["msnfp_transactionid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_transactionid.");
                }
                else
                {
                    mSNFP_Response.TransactionId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_transactionid.");
                }
                if (queriedEntityRecord.Contains("msnfp_response") && queriedEntityRecord["msnfp_response"] != null)
                {
                    mSNFP_Response.Result = (string)queriedEntityRecord["msnfp_response"];
                    localContext.TracingService.Trace("Got msnfp_response.");
                }
                else
                {
                    localContext.TracingService.Trace("Did NOT find msnfp_response.");
                }
                if (queriedEntityRecord.Contains("msnfp_identifier") && queriedEntityRecord["msnfp_identifier"] != null)
                {
                    mSNFP_Response.Identifier = (string)queriedEntityRecord["msnfp_identifier"];
                    localContext.TracingService.Trace("Got msnfp_identifier.");
                }
                else
                {
                    mSNFP_Response.Identifier = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_identifier.");
                }
                if (queriedEntityRecord.Contains("statecode") && queriedEntityRecord["statecode"] != null)
                {
                    mSNFP_Response.StateCode = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                    localContext.TracingService.Trace("Got statecode.");
                }
                else
                {
                    mSNFP_Response.StateCode = null;
                    localContext.TracingService.Trace("Did NOT find statecode.");
                }
                if (queriedEntityRecord.Contains("statuscode") && queriedEntityRecord["statuscode"] != null)
                {
                    mSNFP_Response.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                    localContext.TracingService.Trace("Got statuscode.");
                }
                else
                {
                    mSNFP_Response.StatusCode = null;
                    localContext.TracingService.Trace("Did NOT find statuscode.");
                }
                if (messageName == "Create")
                {
                    mSNFP_Response.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    mSNFP_Response.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                else
                {
                    mSNFP_Response.CreatedOn = null;
                }
                mSNFP_Response.SyncDate = DateTime.UtcNow;
                if (messageName == "Delete")
                {
                    mSNFP_Response.Deleted     = true;
                    mSNFP_Response.DeletedDate = DateTime.UtcNow;
                    localContext.TracingService.Trace("Setting Deleted Date to:" + mSNFP_Response.DeletedDate.ToString());
                }
                else
                {
                    mSNFP_Response.Deleted     = false;
                    mSNFP_Response.DeletedDate = null;
                }
                localContext.TracingService.Trace("JSON object created");
                if (messageName == "Create")
                {
                    text2 = text2 + text + "/Create" + text;
                }
                else if (messageName == "Update" || messageName == "Delete")
                {
                    text2 = text2 + text + "/Update" + text;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_Response));
                localContext.TracingService.Trace("Attempt to create JSON via serialization.");
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_Response);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + text2);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                string str = webAPIClient.UploadString(text2, @string);
                localContext.TracingService.Trace("Got response.");
                localContext.TracingService.Trace("Response: " + str);
            }
            else
            {
                localContext.TracingService.Trace("No API URL or Enable Portal Pages. Exiting workflow.");
            }
        }
        private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, LocalPluginContext localContext, IOrganizationService service, IPluginExecutionContext context)
        {
            localContext.TracingService.Trace("---------Send the Record to Azure---------");
            string messageName = context.MessageName;
            string text        = "EventTicket";
            string text2       = Utilities.GetAzureWebAPIURL(service, context);

            localContext.TracingService.Trace("Got API URL: " + text2);
            if (text2 != string.Empty)
            {
                localContext.TracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord["msnfp_eventticketid"].ToString());
                MSNFP_EventTicket mSNFP_EventTicket = new MSNFP_EventTicket();
                mSNFP_EventTicket.EvenTicketId = (Guid)queriedEntityRecord["msnfp_eventticketid"];
                if (queriedEntityRecord.Contains("msnfp_amount") && queriedEntityRecord["msnfp_amount"] != null)
                {
                    mSNFP_EventTicket.Amount = ((Money)queriedEntityRecord["msnfp_amount"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount");
                }
                else
                {
                    mSNFP_EventTicket.Amount = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_amount.");
                }
                if (queriedEntityRecord.Contains("msnfp_amount_receipted") && queriedEntityRecord["msnfp_amount_receipted"] != null)
                {
                    mSNFP_EventTicket.AmountReceipted = ((Money)queriedEntityRecord["msnfp_amount_receipted"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount_receipted.");
                }
                else
                {
                    mSNFP_EventTicket.AmountReceipted = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_amount_receipted.");
                }
                if (queriedEntityRecord.Contains("msnfp_amount_nonreceiptable") && queriedEntityRecord["msnfp_amount_nonreceiptable"] != null)
                {
                    mSNFP_EventTicket.AmountNonReceiptable = ((Money)queriedEntityRecord["msnfp_amount_nonreceiptable"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount_nonreceiptable.");
                }
                else
                {
                    mSNFP_EventTicket.AmountNonReceiptable = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_amount_nonreceiptable.");
                }
                if (queriedEntityRecord.Contains("msnfp_amount_tax") && queriedEntityRecord["msnfp_amount_tax"] != null)
                {
                    mSNFP_EventTicket.AmountTax = ((Money)queriedEntityRecord["msnfp_amount_tax"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount_tax.");
                }
                else
                {
                    mSNFP_EventTicket.AmountTax = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_amount_tax.");
                }
                if (queriedEntityRecord.Contains("msnfp_description") && queriedEntityRecord["msnfp_description"] != null)
                {
                    mSNFP_EventTicket.Description = (string)queriedEntityRecord["msnfp_description"];
                    localContext.TracingService.Trace("Got msnfp_description.");
                }
                else
                {
                    mSNFP_EventTicket.Description = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_description.");
                }
                if (queriedEntityRecord.Contains("msnfp_eventid") && queriedEntityRecord["msnfp_eventid"] != null)
                {
                    mSNFP_EventTicket.EventId = ((EntityReference)queriedEntityRecord["msnfp_eventid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_eventid.");
                }
                else
                {
                    mSNFP_EventTicket.EventId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_eventid.");
                }
                if (queriedEntityRecord.Contains("msnfp_maxspots") && queriedEntityRecord["msnfp_maxspots"] != null)
                {
                    mSNFP_EventTicket.MaxSpots = (int)queriedEntityRecord["msnfp_maxspots"];
                    localContext.TracingService.Trace("Got msnfp_maxspots.");
                }
                else
                {
                    mSNFP_EventTicket.MaxSpots = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_maxspots.");
                }
                if (queriedEntityRecord.Contains("msnfp_registrationsperticket") && queriedEntityRecord["msnfp_registrationsperticket"] != null)
                {
                    mSNFP_EventTicket.RegistrationsPerTicket = (int)queriedEntityRecord["msnfp_registrationsperticket"];
                    localContext.TracingService.Trace("Got msnfp_registrationsperticket.");
                }
                else
                {
                    mSNFP_EventTicket.RegistrationsPerTicket = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_registrationsperticket.");
                }
                if (queriedEntityRecord.Contains("msnfp_sum_available") && queriedEntityRecord["msnfp_sum_available"] != null)
                {
                    mSNFP_EventTicket.SumAvailable = (int)queriedEntityRecord["msnfp_sum_available"];
                    localContext.TracingService.Trace("Got msnfp_sum_available.");
                }
                else
                {
                    mSNFP_EventTicket.SumAvailable = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_sum_available.");
                }
                if (queriedEntityRecord.Contains("msnfp_sum_sold") && queriedEntityRecord["msnfp_sum_sold"] != null)
                {
                    mSNFP_EventTicket.SumSold = (int)queriedEntityRecord["msnfp_sum_sold"];
                    localContext.TracingService.Trace("Got msnfp_sum_sold.");
                }
                else
                {
                    mSNFP_EventTicket.SumSold = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_sum_sold.");
                }
                if (queriedEntityRecord.Contains("msnfp_tickets") && queriedEntityRecord["msnfp_tickets"] != null)
                {
                    mSNFP_EventTicket.Tickets = (int)queriedEntityRecord["msnfp_tickets"];
                    localContext.TracingService.Trace("Got msnfp_tickets.");
                }
                else
                {
                    mSNFP_EventTicket.Tickets = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_tickets.");
                }
                if (queriedEntityRecord.Contains("msnfp_identifier") && queriedEntityRecord["msnfp_identifier"] != null)
                {
                    mSNFP_EventTicket.Identifier = (string)queriedEntityRecord["msnfp_identifier"];
                    localContext.TracingService.Trace("Got msnfp_identifier.");
                }
                else
                {
                    mSNFP_EventTicket.Identifier = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_identifier.");
                }
                if (queriedEntityRecord.Contains("msnfp_val_sold") && queriedEntityRecord["msnfp_val_sold"] != null)
                {
                    mSNFP_EventTicket.ValTickets = ((Money)queriedEntityRecord["msnfp_val_sold"]).Value;
                    localContext.TracingService.Trace("Got msnfp_val_sold.");
                }
                else
                {
                    mSNFP_EventTicket.ValTickets = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_val_sold.");
                }
                if (queriedEntityRecord.Contains("transactioncurrencyid") && queriedEntityRecord["transactioncurrencyid"] != null)
                {
                    mSNFP_EventTicket.TransactionCurrencyId = ((EntityReference)queriedEntityRecord["transactioncurrencyid"]).Id;
                    localContext.TracingService.Trace("Got transactioncurrencyid.");
                }
                else
                {
                    mSNFP_EventTicket.TransactionCurrencyId = null;
                    localContext.TracingService.Trace("Did NOT find transactioncurrencyid.");
                }
                if (queriedEntityRecord.Contains("statecode") && queriedEntityRecord["statecode"] != null)
                {
                    mSNFP_EventTicket.StateCode = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                    localContext.TracingService.Trace("Got statecode.");
                }
                else
                {
                    mSNFP_EventTicket.StateCode = null;
                    localContext.TracingService.Trace("Did NOT find statecode.");
                }
                if (queriedEntityRecord.Contains("statuscode") && queriedEntityRecord["statuscode"] != null)
                {
                    mSNFP_EventTicket.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                    localContext.TracingService.Trace("Got statuscode.");
                }
                else
                {
                    mSNFP_EventTicket.StatusCode = null;
                    localContext.TracingService.Trace("Did NOT find statuscode.");
                }
                if (messageName == "Create")
                {
                    mSNFP_EventTicket.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    mSNFP_EventTicket.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                else
                {
                    mSNFP_EventTicket.CreatedOn = null;
                }
                mSNFP_EventTicket.SyncDate = DateTime.UtcNow;
                if (messageName == "Delete")
                {
                    mSNFP_EventTicket.Deleted     = true;
                    mSNFP_EventTicket.DeletedDate = DateTime.UtcNow;
                }
                else
                {
                    mSNFP_EventTicket.Deleted     = false;
                    mSNFP_EventTicket.DeletedDate = null;
                }
                localContext.TracingService.Trace("JSON object created");
                if (messageName == "Create")
                {
                    text2 = text2 + text + "/Create" + text;
                }
                else if (messageName == "Update" || messageName == "Delete")
                {
                    text2 = text2 + text + "/Update" + text;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_EventTicket));
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_EventTicket);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + text2);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                string str = webAPIClient.UploadString(text2, @string);
                localContext.TracingService.Trace("Got response.");
                localContext.TracingService.Trace("Response: " + str);
            }
            else
            {
                localContext.TracingService.Trace("No API URL or Enable Portal Pages. Exiting plugin.");
            }
        }
        private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, LocalPluginContext localContext, IOrganizationService service, IPluginExecutionContext context)
        {
            localContext.TracingService.Trace("---------Send the Record to Azure---------");
            string messageName = context.MessageName;
            string text        = "BankRun";
            string text2       = Utilities.GetAzureWebAPIURL(service, context);

            if (text2 != string.Empty)
            {
                localContext.TracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord["msnfp_bankrunid"].ToString());
                MSNFP_BankRun mSNFP_BankRun = new MSNFP_BankRun();
                mSNFP_BankRun.BankRunId  = (Guid)queriedEntityRecord["msnfp_bankrunid"];
                mSNFP_BankRun.Identifier = (queriedEntityRecord.Contains("msnfp_identifier") ? ((string)queriedEntityRecord["msnfp_identifier"]) : string.Empty);
                localContext.TracingService.Trace("Identifier: " + mSNFP_BankRun.Identifier);
                if (queriedEntityRecord.Contains("msnfp_startdate") && queriedEntityRecord["msnfp_startdate"] != null)
                {
                    mSNFP_BankRun.StartDate = (DateTime)queriedEntityRecord["msnfp_startdate"];
                    localContext.TracingService.Trace("Got msnfp_startdate.");
                }
                else
                {
                    mSNFP_BankRun.StartDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_startdate.");
                }
                if (queriedEntityRecord.Contains("msnfp_enddate") && queriedEntityRecord["msnfp_enddate"] != null)
                {
                    mSNFP_BankRun.EndDate = (DateTime)queriedEntityRecord["msnfp_enddate"];
                    localContext.TracingService.Trace("Got msnfp_enddate.");
                }
                else
                {
                    mSNFP_BankRun.EndDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_enddate.");
                }
                if (queriedEntityRecord.Contains("msnfp_datetobeprocessed") && queriedEntityRecord["msnfp_datetobeprocessed"] != null)
                {
                    mSNFP_BankRun.DateToBeProcessed = (DateTime)queriedEntityRecord["msnfp_datetobeprocessed"];
                    localContext.TracingService.Trace("Got msnfp_datetobeprocessed.");
                }
                else
                {
                    mSNFP_BankRun.DateToBeProcessed = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_datetobeprocessed.");
                }
                if (queriedEntityRecord.Contains("msnfp_bankrunstatus") && queriedEntityRecord["msnfp_bankrunstatus"] != null)
                {
                    mSNFP_BankRun.BankRunStatus = ((OptionSetValue)queriedEntityRecord["msnfp_bankrunstatus"]).Value;
                    localContext.TracingService.Trace("Got msnfp_bankrunstatus.");
                }
                else
                {
                    mSNFP_BankRun.BankRunStatus = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_bankrunstatus.");
                }
                if (queriedEntityRecord.Contains("msnfp_accounttocreditid") && queriedEntityRecord["msnfp_accounttocreditid"] != null)
                {
                    mSNFP_BankRun.AccountToCreditId = ((EntityReference)queriedEntityRecord["msnfp_accounttocreditid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_accounttocreditid");
                }
                else
                {
                    mSNFP_BankRun.AccountToCreditId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_accounttocreditid");
                }
                if (queriedEntityRecord.Contains("msnfp_paymentprocessorid") && queriedEntityRecord["msnfp_paymentprocessorid"] != null)
                {
                    mSNFP_BankRun.PaymentProcessorId = ((EntityReference)queriedEntityRecord["msnfp_paymentprocessorid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_paymentprocessorid");
                }
                else
                {
                    mSNFP_BankRun.PaymentProcessorId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_paymentprocessorid");
                }
                if (queriedEntityRecord.Contains("msnfp_filecreationnumber") && queriedEntityRecord["msnfp_filecreationnumber"] != null)
                {
                    mSNFP_BankRun.FileCreationNumber = (int)queriedEntityRecord["msnfp_filecreationnumber"];
                    localContext.TracingService.Trace("Got msnfp_filecreationnumber");
                }
                else
                {
                    mSNFP_BankRun.FileCreationNumber = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_filecreationnumber");
                }
                if (messageName == "Create")
                {
                    mSNFP_BankRun.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    mSNFP_BankRun.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                else
                {
                    mSNFP_BankRun.CreatedOn = null;
                }
                if (messageName == "Delete")
                {
                    mSNFP_BankRun.Deleted     = true;
                    mSNFP_BankRun.DeletedDate = DateTime.UtcNow;
                }
                else
                {
                    mSNFP_BankRun.Deleted     = false;
                    mSNFP_BankRun.DeletedDate = null;
                }
                mSNFP_BankRun.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                mSNFP_BankRun.StateCode  = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                localContext.TracingService.Trace("JSON object created");
                if (messageName == "Create")
                {
                    text2 = text2 + text + "/Create" + text;
                }
                else if (messageName == "Update" || messageName == "Delete")
                {
                    text2 = text2 + text + "/Update" + text;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_BankRun));
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_BankRun);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + text2);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                string text3 = webAPIClient.UploadString(text2, @string);
                localContext.TracingService.Trace("Got response.");
                localContext.TracingService.Trace("Response: " + text3);
                Utilities utilities = new Utilities();
                utilities.CheckAPIReturnJSONForErrors(text3, configurationRecord.GetAttributeValue <OptionSetValue>("msnfp_showapierrorresponses"), localContext.TracingService);
            }
            else
            {
                localContext.TracingService.Trace("No API URL or Enable Portal Pages. Exiting workflow.");
            }
        }
        private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, LocalPluginContext localContext, IOrganizationService service, IPluginExecutionContext context)
        {
            localContext.TracingService.Trace("---------Send the Record to Azure---------");
            string messageName = context.MessageName;
            string text        = "ReceiptStack";
            string text2       = Utilities.GetAzureWebAPIURL(service, context);

            localContext.TracingService.Trace("Got API URL: " + text2);
            if (text2 != string.Empty)
            {
                localContext.TracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord["msnfp_receiptstackid"].ToString());
                MSNFP_ReceiptStack mSNFP_ReceiptStack = new MSNFP_ReceiptStack();
                mSNFP_ReceiptStack.ReceiptStackId = (Guid)queriedEntityRecord["msnfp_receiptstackid"];
                mSNFP_ReceiptStack.Identifier     = (queriedEntityRecord.Contains("msnfp_identifier") ? ((string)queriedEntityRecord["msnfp_identifier"]) : string.Empty);
                localContext.TracingService.Trace("Title: " + mSNFP_ReceiptStack.Identifier);
                if (queriedEntityRecord.Contains("msnfp_configurationid") && queriedEntityRecord["msnfp_configurationid"] != null)
                {
                    mSNFP_ReceiptStack.ConfigurationId = ((EntityReference)queriedEntityRecord["msnfp_configurationid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_configurationid.");
                }
                else
                {
                    mSNFP_ReceiptStack.ConfigurationId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_configurationid.");
                }
                if (queriedEntityRecord.Contains("msnfp_currentrange") && queriedEntityRecord["msnfp_currentrange"] != null)
                {
                    mSNFP_ReceiptStack.CurrentRange = (double)queriedEntityRecord["msnfp_currentrange"];
                    localContext.TracingService.Trace("Got msnfp_currentrange.");
                }
                else
                {
                    mSNFP_ReceiptStack.CurrentRange = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_currentrange.");
                }
                if (queriedEntityRecord.Contains("msnfp_numberrange") && queriedEntityRecord["msnfp_numberrange"] != null)
                {
                    mSNFP_ReceiptStack.NumberRange = ((OptionSetValue)queriedEntityRecord["msnfp_numberrange"]).Value;
                    localContext.TracingService.Trace("Got msnfp_numberrange.");
                }
                else
                {
                    mSNFP_ReceiptStack.NumberRange = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_numberrange.");
                }
                if (queriedEntityRecord.Contains("msnfp_prefix") && queriedEntityRecord["msnfp_prefix"] != null)
                {
                    mSNFP_ReceiptStack.Prefix = (string)queriedEntityRecord["msnfp_prefix"];
                    localContext.TracingService.Trace("Got msnfp_prefix.");
                }
                else
                {
                    mSNFP_ReceiptStack.Prefix = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_prefix.");
                }
                if (queriedEntityRecord.Contains("msnfp_receiptyear") && queriedEntityRecord["msnfp_receiptyear"] != null)
                {
                    mSNFP_ReceiptStack.ReceiptYear = ((OptionSetValue)queriedEntityRecord["msnfp_receiptyear"]).Value;
                    localContext.TracingService.Trace("Got msnfp_receiptyear.");
                }
                else
                {
                    mSNFP_ReceiptStack.ReceiptYear = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_receiptyear.");
                }
                if (queriedEntityRecord.Contains("msnfp_startingrange") && queriedEntityRecord["msnfp_startingrange"] != null)
                {
                    mSNFP_ReceiptStack.StartingRange = (double)queriedEntityRecord["msnfp_startingrange"];
                    localContext.TracingService.Trace("Got msnfp_startingrange.");
                }
                else
                {
                    mSNFP_ReceiptStack.StartingRange = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_startingrange.");
                }
                if (queriedEntityRecord.Contains("statecode") && queriedEntityRecord["statecode"] != null)
                {
                    mSNFP_ReceiptStack.StateCode = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                    localContext.TracingService.Trace("Got statecode.");
                }
                else
                {
                    mSNFP_ReceiptStack.StateCode = null;
                    localContext.TracingService.Trace("Did NOT find statecode.");
                }
                if (queriedEntityRecord.Contains("statuscode") && queriedEntityRecord["statuscode"] != null)
                {
                    mSNFP_ReceiptStack.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                    localContext.TracingService.Trace("Got statuscode.");
                }
                else
                {
                    mSNFP_ReceiptStack.StatusCode = null;
                    localContext.TracingService.Trace("Did NOT find statuscode.");
                }
                if (messageName == "Create")
                {
                    mSNFP_ReceiptStack.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    mSNFP_ReceiptStack.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                else
                {
                    mSNFP_ReceiptStack.CreatedOn = null;
                }
                mSNFP_ReceiptStack.SyncDate = DateTime.UtcNow;
                if (messageName == "Delete")
                {
                    mSNFP_ReceiptStack.Deleted     = true;
                    mSNFP_ReceiptStack.DeletedDate = DateTime.UtcNow;
                }
                else
                {
                    mSNFP_ReceiptStack.Deleted     = false;
                    mSNFP_ReceiptStack.DeletedDate = null;
                }
                mSNFP_ReceiptStack.Configuration = null;
                mSNFP_ReceiptStack.Receipt       = new HashSet <MSNFP_Receipt>();
                mSNFP_ReceiptStack.ReceiptLog    = new HashSet <MSNFP_ReceiptLog>();
                localContext.TracingService.Trace("JSON object created");
                if (messageName == "Create")
                {
                    text2 = text2 + text + "/Create" + text;
                }
                else if (messageName == "Update" || messageName == "Delete")
                {
                    text2 = text2 + text + "/Update" + text;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_ReceiptStack));
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_ReceiptStack);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + text2);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                string text3 = webAPIClient.UploadString(text2, @string);
                localContext.TracingService.Trace("Got response.");
                localContext.TracingService.Trace("Response: " + text3);
                Utilities utilities = new Utilities();
                utilities.CheckAPIReturnJSONForErrors(text3, configurationRecord.GetAttributeValue <OptionSetValue>("msnfp_showapierrorresponses"), localContext.TracingService);
            }
            else
            {
                localContext.TracingService.Trace("No API URL or Enable Portal Pages. Exiting workflow.");
            }
        }
        private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, LocalPluginContext localContext, IOrganizationService service, IPluginExecutionContext context)
        {
            localContext.TracingService.Trace("---------Send the Record to Azure---------");
            string messageName = context.MessageName;
            string text        = "Receipt";
            string text2       = Utilities.GetAzureWebAPIURL(service, context);

            localContext.TracingService.Trace("Got API URL: " + text2);
            if (text2 != string.Empty)
            {
                localContext.TracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord["msnfp_receiptid"].ToString());
                MSNFP_Receipt mSNFP_Receipt = new MSNFP_Receipt();
                mSNFP_Receipt.ReceiptId  = (Guid)queriedEntityRecord["msnfp_receiptid"];
                mSNFP_Receipt.Identifier = (queriedEntityRecord.Contains("msnfp_identifier") ? ((string)queriedEntityRecord["msnfp_identifier"]) : string.Empty);
                localContext.TracingService.Trace("Title: " + mSNFP_Receipt.Identifier);
                if (queriedEntityRecord.Contains("msnfp_customerid") && queriedEntityRecord["msnfp_customerid"] != null)
                {
                    mSNFP_Receipt.CustomerId = ((EntityReference)queriedEntityRecord["msnfp_customerid"]).Id;
                    if (((EntityReference)queriedEntityRecord["msnfp_customerid"]).LogicalName.ToLower() == "contact")
                    {
                        mSNFP_Receipt.CustomerIdType = 2;
                    }
                    else if (((EntityReference)queriedEntityRecord["msnfp_customerid"]).LogicalName.ToLower() == "account")
                    {
                        mSNFP_Receipt.CustomerIdType = 1;
                    }
                    localContext.TracingService.Trace("Got msnfp_customerid.");
                }
                else
                {
                    mSNFP_Receipt.CustomerId     = null;
                    mSNFP_Receipt.CustomerIdType = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_customerid.");
                }
                if (queriedEntityRecord.Contains("msnfp_expectedtaxcredit") && queriedEntityRecord["msnfp_expectedtaxcredit"] != null)
                {
                    mSNFP_Receipt.ExpectedTaxCredit = ((Money)queriedEntityRecord["msnfp_expectedtaxcredit"]).Value;
                    localContext.TracingService.Trace("Got msnfp_expectedtaxcredit.");
                }
                else
                {
                    mSNFP_Receipt.ExpectedTaxCredit = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_expectedtaxcredit.");
                }
                if (queriedEntityRecord.Contains("msnfp_generatedorprinted") && queriedEntityRecord["msnfp_generatedorprinted"] != null)
                {
                    mSNFP_Receipt.GeneratedorPrinted = (double)queriedEntityRecord["msnfp_generatedorprinted"];
                    localContext.TracingService.Trace("Got msnfp_generatedorprinted.");
                }
                else
                {
                    mSNFP_Receipt.GeneratedorPrinted = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_generatedorprinted.");
                }
                if (queriedEntityRecord.Contains("msnfp_lastdonationdate") && queriedEntityRecord["msnfp_lastdonationdate"] != null)
                {
                    mSNFP_Receipt.LastDonationDate = (DateTime)queriedEntityRecord["msnfp_lastdonationdate"];
                    localContext.TracingService.Trace("Got msnfp_lastdonationdate.");
                }
                else
                {
                    mSNFP_Receipt.LastDonationDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_lastdonationdate.");
                }
                if (queriedEntityRecord.Contains("msnfp_amount_nonreceiptable") && queriedEntityRecord["msnfp_amount_nonreceiptable"] != null)
                {
                    mSNFP_Receipt.AmountNonReceiptable = ((Money)queriedEntityRecord["msnfp_amount_nonreceiptable"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount_nonreceiptable.");
                }
                else
                {
                    mSNFP_Receipt.AmountNonReceiptable = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_amount_nonreceiptable.");
                }
                if (queriedEntityRecord.Contains("msnfp_transactioncount") && queriedEntityRecord["msnfp_transactioncount"] != null)
                {
                    mSNFP_Receipt.TransactionCount = (int)queriedEntityRecord["msnfp_transactioncount"];
                    localContext.TracingService.Trace("Got msnfp_transactioncount.");
                }
                else
                {
                    mSNFP_Receipt.TransactionCount = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_transactioncount.");
                }
                if (queriedEntityRecord.Contains("msnfp_preferredlanguagecode") && queriedEntityRecord["msnfp_preferredlanguagecode"] != null)
                {
                    mSNFP_Receipt.PreferredLanguageCode = ((OptionSetValue)queriedEntityRecord["msnfp_preferredlanguagecode"]).Value;
                    localContext.TracingService.Trace("Got msnfp_preferredlanguagecode.");
                }
                else
                {
                    mSNFP_Receipt.PreferredLanguageCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_preferredlanguagecode.");
                }
                if (queriedEntityRecord.Contains("msnfp_receiptnumber") && queriedEntityRecord["msnfp_receiptnumber"] != null)
                {
                    mSNFP_Receipt.ReceiptNumber = (string)queriedEntityRecord["msnfp_receiptnumber"];
                    localContext.TracingService.Trace("Got msnfp_receiptnumber.");
                }
                else
                {
                    mSNFP_Receipt.ReceiptNumber = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_receiptnumber.");
                }
                if (queriedEntityRecord.Contains("msnfp_receiptgeneration") && queriedEntityRecord["msnfp_receiptgeneration"] != null)
                {
                    mSNFP_Receipt.ReceiptGeneration = ((OptionSetValue)queriedEntityRecord["msnfp_receiptgeneration"]).Value;
                    localContext.TracingService.Trace("Got msnfp_receiptgeneration.");
                }
                else
                {
                    mSNFP_Receipt.ReceiptGeneration = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_receiptgeneration.");
                }
                if (queriedEntityRecord.Contains("msnfp_receiptissuedate") && queriedEntityRecord["msnfp_receiptissuedate"] != null)
                {
                    mSNFP_Receipt.ReceiptIssueDate = (DateTime)queriedEntityRecord["msnfp_receiptissuedate"];
                    localContext.TracingService.Trace("Got msnfp_receiptissuedate.");
                }
                else
                {
                    mSNFP_Receipt.ReceiptIssueDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_receiptissuedate.");
                }
                if (queriedEntityRecord.Contains("msnfp_receiptstackid") && queriedEntityRecord["msnfp_receiptstackid"] != null)
                {
                    mSNFP_Receipt.ReceiptStackId = ((EntityReference)queriedEntityRecord["msnfp_receiptstackid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_receiptstackid.");
                }
                else
                {
                    mSNFP_Receipt.ReceiptStackId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_receiptstackid.");
                }
                if (queriedEntityRecord.Contains("msnfp_receiptstatus") && queriedEntityRecord["msnfp_receiptstatus"] != null)
                {
                    mSNFP_Receipt.ReceiptStatus = (string)queriedEntityRecord["msnfp_receiptstatus"];
                    localContext.TracingService.Trace("Got msnfp_receiptstatus.");
                }
                else
                {
                    mSNFP_Receipt.ReceiptStatus = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_receiptstatus.");
                }
                if (queriedEntityRecord.Contains("msnfp_amount_receipted") && queriedEntityRecord["msnfp_amount_receipted"] != null)
                {
                    mSNFP_Receipt.AmountReceipted = ((Money)queriedEntityRecord["msnfp_amount_receipted"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount_receipted.");
                }
                else
                {
                    mSNFP_Receipt.AmountReceipted = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_amount_receipted.");
                }
                if (queriedEntityRecord.Contains("msnfp_paymentscheduleid") && queriedEntityRecord["msnfp_paymentscheduleid"] != null)
                {
                    mSNFP_Receipt.PaymentScheduleId = ((EntityReference)queriedEntityRecord["msnfp_paymentscheduleid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_paymentscheduleid.");
                }
                else
                {
                    mSNFP_Receipt.PaymentScheduleId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_paymentscheduleid.");
                }
                if (queriedEntityRecord.Contains("msnfp_replacesreceiptid") && queriedEntityRecord["msnfp_replacesreceiptid"] != null)
                {
                    mSNFP_Receipt.ReplacesReceiptId = ((EntityReference)queriedEntityRecord["msnfp_replacesreceiptid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_replacesreceiptid.");
                }
                else
                {
                    mSNFP_Receipt.ReplacesReceiptId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_replacesreceiptid.");
                }
                if (queriedEntityRecord.Contains("msnfp_replacesreceiptid") && queriedEntityRecord["msnfp_replacesreceiptid"] != null)
                {
                    mSNFP_Receipt.ReplacesReceiptId = ((EntityReference)queriedEntityRecord["msnfp_replacesreceiptid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_replacesreceiptid.");
                }
                else
                {
                    mSNFP_Receipt.ReplacesReceiptId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_replacesreceiptid.");
                }
                if (queriedEntityRecord.Contains("msnfp_amount") && queriedEntityRecord["msnfp_amount"] != null)
                {
                    mSNFP_Receipt.Amount = ((Money)queriedEntityRecord["msnfp_amount"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount.");
                }
                else
                {
                    mSNFP_Receipt.Amount = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_amount.");
                }
                if (queriedEntityRecord.Contains("transactioncurrencyid") && queriedEntityRecord["transactioncurrencyid"] != null)
                {
                    mSNFP_Receipt.TransactionCurrencyId = ((EntityReference)queriedEntityRecord["transactioncurrencyid"]).Id;
                    localContext.TracingService.Trace("Got TransactionCurrencyId.");
                }
                else
                {
                    mSNFP_Receipt.TransactionCurrencyId = null;
                    localContext.TracingService.Trace("Did NOT find TransactionCurrencyId.");
                }
                if (queriedEntityRecord.Contains("msnfp_printed") && queriedEntityRecord["msnfp_printed"] != null)
                {
                    mSNFP_Receipt.Printed = (DateTime)queriedEntityRecord["msnfp_printed"];
                    localContext.TracingService.Trace("Got Printed.");
                }
                else
                {
                    mSNFP_Receipt.Printed = null;
                    localContext.TracingService.Trace("Did NOT find Printed.");
                }
                if (queriedEntityRecord.Contains("msnfp_deliverycode") && queriedEntityRecord["msnfp_deliverycode"] != null)
                {
                    mSNFP_Receipt.DeliveryCode = ((OptionSetValue)queriedEntityRecord["msnfp_deliverycode"]).Value;
                    localContext.TracingService.Trace("Got Delivery.");
                }
                else
                {
                    mSNFP_Receipt.DeliveryCode = null;
                    localContext.TracingService.Trace("Did NOT find Delivery.");
                }
                if (queriedEntityRecord.Contains("msnfp_emaildeliverystatuscode") && queriedEntityRecord["msnfp_emaildeliverystatuscode"] != null)
                {
                    mSNFP_Receipt.EmailDeliveryStatusCode = ((OptionSetValue)queriedEntityRecord["msnfp_emaildeliverystatuscode"]).Value;
                    localContext.TracingService.Trace("Got EmailDeliveryStatus.");
                }
                else
                {
                    mSNFP_Receipt.EmailDeliveryStatusCode = null;
                    localContext.TracingService.Trace("Did NOT find EmailDeliveryStatus.");
                }
                if (queriedEntityRecord.Contains("statecode") && queriedEntityRecord["statecode"] != null)
                {
                    mSNFP_Receipt.StateCode = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                    localContext.TracingService.Trace("Got statecode.");
                }
                else
                {
                    mSNFP_Receipt.StateCode = null;
                    localContext.TracingService.Trace("Did NOT find statecode.");
                }
                if (queriedEntityRecord.Contains("statuscode") && queriedEntityRecord["statuscode"] != null)
                {
                    mSNFP_Receipt.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                    localContext.TracingService.Trace("Got statuscode.");
                }
                else
                {
                    mSNFP_Receipt.StatusCode = null;
                    localContext.TracingService.Trace("Did NOT find statuscode.");
                }
                if (messageName == "Create")
                {
                    mSNFP_Receipt.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    mSNFP_Receipt.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                else
                {
                    mSNFP_Receipt.CreatedOn = null;
                }
                mSNFP_Receipt.SyncDate = DateTime.UtcNow;
                if (messageName == "Delete")
                {
                    mSNFP_Receipt.Deleted     = true;
                    mSNFP_Receipt.DeletedDate = DateTime.UtcNow;
                }
                else
                {
                    mSNFP_Receipt.Deleted     = false;
                    mSNFP_Receipt.DeletedDate = null;
                }
                mSNFP_Receipt.PaymentSchedule        = null;
                mSNFP_Receipt.ReceiptStack           = null;
                mSNFP_Receipt.ReplacesReceipt        = null;
                mSNFP_Receipt.InverseReplacesReceipt = new HashSet <MSNFP_Receipt>();
                localContext.TracingService.Trace("JSON object created");
                if (messageName == "Create")
                {
                    text2 = text2 + text + "/Create" + text;
                }
                else if (messageName == "Update" || messageName == "Delete")
                {
                    text2 = text2 + text + "/Update" + text;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_Receipt));
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_Receipt);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + text2);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                string str = webAPIClient.UploadString(text2, @string);
                localContext.TracingService.Trace("Got response.");
                localContext.TracingService.Trace("Response: " + str);
            }
            else
            {
                localContext.TracingService.Trace("No API URL or Enable Portal Pages. Exiting workflow.");
            }
        }
예제 #6
0
        private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, LocalPluginContext localContext, IOrganizationService service, IPluginExecutionContext context)
        {
            localContext.TracingService.Trace("---------Send the Record to Azure---------");
            string messageName = context.MessageName;
            string text        = "PaymentSchedule";
            string text2       = Utilities.GetAzureWebAPIURL(service, context);

            localContext.TracingService.Trace("Got API URL: " + text2);
            if (text2 != string.Empty)
            {
                localContext.TracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord["msnfp_paymentscheduleid"].ToString());
                MSNFP_PaymentSchedule mSNFP_PaymentSchedule = new MSNFP_PaymentSchedule();
                mSNFP_PaymentSchedule.PaymentScheduleId = (Guid)queriedEntityRecord["msnfp_paymentscheduleid"];
                mSNFP_PaymentSchedule.Name = (queriedEntityRecord.Contains("msnfp_name") ? ((string)queriedEntityRecord["msnfp_name"]) : string.Empty);
                localContext.TracingService.Trace("Title: " + mSNFP_PaymentSchedule.Name);
                if (queriedEntityRecord.Contains("msnfp_amount_receipted") && queriedEntityRecord["msnfp_amount_receipted"] != null)
                {
                    mSNFP_PaymentSchedule.AmountReceipted = ((Money)queriedEntityRecord["msnfp_amount_receipted"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount_receipted.");
                }
                else
                {
                    mSNFP_PaymentSchedule.AmountReceipted = default(decimal);
                    localContext.TracingService.Trace("Did NOT find msnfp_amount_receipted.");
                }
                if (queriedEntityRecord.Contains("msnfp_amount_membership") && queriedEntityRecord["msnfp_amount_membership"] != null)
                {
                    mSNFP_PaymentSchedule.AmountMembership = ((Money)queriedEntityRecord["msnfp_amount_membership"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount_membership.");
                }
                else
                {
                    mSNFP_PaymentSchedule.AmountMembership = default(decimal);
                    localContext.TracingService.Trace("Did NOT find msnfp_amount_membership.");
                }
                if (queriedEntityRecord.Contains("msnfp_amount_nonreceiptable") && queriedEntityRecord["msnfp_amount_nonreceiptable"] != null)
                {
                    mSNFP_PaymentSchedule.AmountNonReceiptable = ((Money)queriedEntityRecord["msnfp_amount_nonreceiptable"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount_nonreceiptable.");
                }
                else
                {
                    mSNFP_PaymentSchedule.AmountNonReceiptable = default(decimal);
                    localContext.TracingService.Trace("Did NOT find msnfp_amount_nonreceiptable.");
                }
                if (queriedEntityRecord.Contains("msnfp_amount_tax") && queriedEntityRecord["msnfp_amount_tax"] != null)
                {
                    mSNFP_PaymentSchedule.AmountTax = ((Money)queriedEntityRecord["msnfp_amount_tax"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount_tax.");
                }
                else
                {
                    mSNFP_PaymentSchedule.AmountTax = default(decimal);
                    localContext.TracingService.Trace("Did NOT find msnfp_amount_tax.");
                }
                if (queriedEntityRecord.Contains("msnfp_recurringamount") && queriedEntityRecord["msnfp_recurringamount"] != null)
                {
                    mSNFP_PaymentSchedule.RecurringAmount = ((Money)queriedEntityRecord["msnfp_recurringamount"]).Value;
                    localContext.TracingService.Trace("Got msnfp_recurringamount.");
                }
                else
                {
                    mSNFP_PaymentSchedule.RecurringAmount = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_recurringamount.");
                }
                if (queriedEntityRecord.Contains("msnfp_firstpaymentdate") && queriedEntityRecord["msnfp_firstpaymentdate"] != null)
                {
                    mSNFP_PaymentSchedule.FirstPaymentDate = (DateTime)queriedEntityRecord["msnfp_firstpaymentdate"];
                    localContext.TracingService.Trace("Got msnfp_firstpaymentdate.");
                }
                else
                {
                    mSNFP_PaymentSchedule.FirstPaymentDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_firstpaymentdate.");
                }
                if (queriedEntityRecord.Contains("msnfp_frequencyinterval") && queriedEntityRecord["msnfp_frequencyinterval"] != null)
                {
                    mSNFP_PaymentSchedule.FrequencyInterval = (int)queriedEntityRecord["msnfp_frequencyinterval"];
                    localContext.TracingService.Trace("Got msnfp_frequencyinterval.");
                }
                else
                {
                    mSNFP_PaymentSchedule.FrequencyInterval = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_frequencyinterval.");
                }
                if (queriedEntityRecord.Contains("msnfp_frequency") && queriedEntityRecord["msnfp_frequency"] != null)
                {
                    mSNFP_PaymentSchedule.Frequency = ((OptionSetValue)queriedEntityRecord["msnfp_frequency"]).Value;
                    localContext.TracingService.Trace("Got msnfp_frequency.");
                }
                else
                {
                    mSNFP_PaymentSchedule.Frequency = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_frequency.");
                }
                if (queriedEntityRecord.Contains("msnfp_nextpaymentdate") && queriedEntityRecord["msnfp_nextpaymentdate"] != null)
                {
                    mSNFP_PaymentSchedule.NextPaymentDate = (DateTime)queriedEntityRecord["msnfp_nextpaymentdate"];
                    localContext.TracingService.Trace("Got msnfp_nextpaymentdate.");
                }
                else
                {
                    mSNFP_PaymentSchedule.NextPaymentDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_nextpaymentdate.");
                }
                if (queriedEntityRecord.Contains("msnfp_frequencystartcode") && queriedEntityRecord["msnfp_frequencystartcode"] != null)
                {
                    mSNFP_PaymentSchedule.FrequencyStartCode = ((OptionSetValue)queriedEntityRecord["msnfp_frequencystartcode"]).Value;
                    localContext.TracingService.Trace("Got msnfp_frequencystartcode.");
                }
                else
                {
                    mSNFP_PaymentSchedule.FrequencyStartCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_frequencystartcode.");
                }
                if (queriedEntityRecord.Contains("msnfp_cancelationcode") && queriedEntityRecord["msnfp_cancelationcode"] != null)
                {
                    mSNFP_PaymentSchedule.CancelationCode = ((OptionSetValue)queriedEntityRecord["msnfp_cancelationcode"]).Value;
                    localContext.TracingService.Trace("Got msnfp_cancelationcode.");
                }
                else
                {
                    mSNFP_PaymentSchedule.CancelationCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_cancelationcode.");
                }
                if (queriedEntityRecord.Contains("msnfp_cancellationnote") && queriedEntityRecord["msnfp_cancellationnote"] != null)
                {
                    mSNFP_PaymentSchedule.CancellationNote = (string)queriedEntityRecord["msnfp_cancellationnote"];
                    localContext.TracingService.Trace("Got msnfp_cancellationnote.");
                }
                else
                {
                    mSNFP_PaymentSchedule.CancellationNote = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_cancellationnote.");
                }
                if (queriedEntityRecord.Contains("msnfp_cancelledon") && queriedEntityRecord["msnfp_cancelledon"] != null)
                {
                    mSNFP_PaymentSchedule.CancelledOn = (DateTime)queriedEntityRecord["msnfp_cancelledon"];
                    localContext.TracingService.Trace("Got msnfp_cancelledon.");
                }
                else
                {
                    mSNFP_PaymentSchedule.CancelledOn = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_cancelledon.");
                }
                if (queriedEntityRecord.Contains("msnfp_endondate") && queriedEntityRecord["msnfp_endondate"] != null)
                {
                    mSNFP_PaymentSchedule.EndonDate = (DateTime)queriedEntityRecord["msnfp_endondate"];
                    localContext.TracingService.Trace("Got msnfp_endondate.");
                }
                else
                {
                    mSNFP_PaymentSchedule.EndonDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_endondate.");
                }
                if (queriedEntityRecord.Contains("msnfp_lastpaymentdate") && queriedEntityRecord["msnfp_lastpaymentdate"] != null)
                {
                    mSNFP_PaymentSchedule.LastPaymentDate = (DateTime)queriedEntityRecord["msnfp_lastpaymentdate"];
                    localContext.TracingService.Trace("Got msnfp_lastpaymentdate.");
                }
                else
                {
                    mSNFP_PaymentSchedule.LastPaymentDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_lastpaymentdate.");
                }
                if (queriedEntityRecord.Contains("msnfp_scheduletypecode") && queriedEntityRecord["msnfp_scheduletypecode"] != null)
                {
                    mSNFP_PaymentSchedule.ScheduleTypeCode = ((OptionSetValue)queriedEntityRecord["msnfp_scheduletypecode"]).Value;
                    localContext.TracingService.Trace("Got msnfp_scheduletypecode.");
                }
                else
                {
                    mSNFP_PaymentSchedule.ScheduleTypeCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_scheduletypecode.");
                }
                if (queriedEntityRecord.Contains("msnfp_anonymity") && queriedEntityRecord["msnfp_anonymity"] != null)
                {
                    mSNFP_PaymentSchedule.Anonymity = ((OptionSetValue)queriedEntityRecord["msnfp_anonymity"]).Value;
                    localContext.TracingService.Trace("Got msnfp_anonymity.");
                }
                else
                {
                    mSNFP_PaymentSchedule.Anonymity = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_anonymity.");
                }
                if (queriedEntityRecord.Contains("msnfp_paymentmethodid") && queriedEntityRecord["msnfp_paymentmethodid"] != null)
                {
                    mSNFP_PaymentSchedule.PaymentMethodId = ((EntityReference)queriedEntityRecord["msnfp_paymentmethodid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_paymentmethodid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.PaymentMethodId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_paymentmethodid.");
                }
                if (queriedEntityRecord.Contains("msnfp_designationid") && queriedEntityRecord["msnfp_designationid"] != null)
                {
                    mSNFP_PaymentSchedule.DesignationId = ((EntityReference)queriedEntityRecord["msnfp_designationid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_designationid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.DesignationId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_designationid.");
                }
                if (queriedEntityRecord.Contains("msnfp_appealid") && queriedEntityRecord["msnfp_appealid"] != null)
                {
                    mSNFP_PaymentSchedule.AppealId = ((EntityReference)queriedEntityRecord["msnfp_appealid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_appealid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.AppealId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_appealid.");
                }
                if (queriedEntityRecord.Contains("msnfp_appraiser") && queriedEntityRecord["msnfp_appraiser"] != null)
                {
                    mSNFP_PaymentSchedule.Appraiser = (string)queriedEntityRecord["msnfp_appraiser"];
                    localContext.TracingService.Trace("Got msnfp_appraiser.");
                }
                else
                {
                    mSNFP_PaymentSchedule.Appraiser = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_appraiser.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_city") && queriedEntityRecord["msnfp_billing_city"] != null)
                {
                    mSNFP_PaymentSchedule.BillingCity = (string)queriedEntityRecord["msnfp_billing_city"];
                    localContext.TracingService.Trace("Got msnfp_billing_city.");
                }
                else
                {
                    mSNFP_PaymentSchedule.BillingCity = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_city.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_country") && queriedEntityRecord["msnfp_billing_country"] != null)
                {
                    mSNFP_PaymentSchedule.BillingCountry = (string)queriedEntityRecord["msnfp_billing_country"];
                    localContext.TracingService.Trace("Got msnfp_billing_country.");
                }
                else
                {
                    mSNFP_PaymentSchedule.BillingCountry = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_country.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_line1") && queriedEntityRecord["msnfp_billing_line1"] != null)
                {
                    mSNFP_PaymentSchedule.BillingLine1 = (string)queriedEntityRecord["msnfp_billing_line1"];
                    localContext.TracingService.Trace("Got msnfp_billing_line1.");
                }
                else
                {
                    mSNFP_PaymentSchedule.BillingLine1 = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_line1.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_line2") && queriedEntityRecord["msnfp_billing_line2"] != null)
                {
                    mSNFP_PaymentSchedule.BillingLine2 = (string)queriedEntityRecord["msnfp_billing_line2"];
                    localContext.TracingService.Trace("Got msnfp_billing_line2.");
                }
                else
                {
                    mSNFP_PaymentSchedule.BillingLine2 = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_line2.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_line3") && queriedEntityRecord["msnfp_billing_line3"] != null)
                {
                    mSNFP_PaymentSchedule.BillingLine3 = (string)queriedEntityRecord["msnfp_billing_line3"];
                    localContext.TracingService.Trace("Got msnfp_billing_line3.");
                }
                else
                {
                    mSNFP_PaymentSchedule.BillingLine3 = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_line3.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_postalcode") && queriedEntityRecord["msnfp_billing_postalcode"] != null)
                {
                    mSNFP_PaymentSchedule.BillingPostalCode = (string)queriedEntityRecord["msnfp_billing_postalcode"];
                    localContext.TracingService.Trace("Got msnfp_billing_postalcode.");
                }
                else
                {
                    mSNFP_PaymentSchedule.BillingPostalCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_postalcode.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_stateorprovince") && queriedEntityRecord["msnfp_billing_stateorprovince"] != null)
                {
                    mSNFP_PaymentSchedule.BillingStateorProvince = (string)queriedEntityRecord["msnfp_billing_stateorprovince"];
                    localContext.TracingService.Trace("Got msnfp_billing_stateorprovince.");
                }
                else
                {
                    mSNFP_PaymentSchedule.BillingStateorProvince = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_stateorprovince.");
                }
                if (queriedEntityRecord.Contains("msnfp_originatingcampaignid") && queriedEntityRecord["msnfp_originatingcampaignid"] != null)
                {
                    mSNFP_PaymentSchedule.OriginatingCampaignId = ((EntityReference)queriedEntityRecord["msnfp_originatingcampaignid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_originatingcampaignid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.OriginatingCampaignId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_originatingcampaignid.");
                }
                if (queriedEntityRecord.Contains("msnfp_ccbrandcode") && queriedEntityRecord["msnfp_ccbrandcode"] != null)
                {
                    mSNFP_PaymentSchedule.CcBrandCode = ((OptionSetValue)queriedEntityRecord["msnfp_ccbrandcode"]).Value;
                    localContext.TracingService.Trace("Got msnfp_ccbrandcode.");
                }
                else
                {
                    mSNFP_PaymentSchedule.CcBrandCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_ccbrandcode.");
                }
                if (queriedEntityRecord.Contains("msnfp_chargeoncreate") && queriedEntityRecord["msnfp_chargeoncreate"] != null)
                {
                    mSNFP_PaymentSchedule.ChargeonCreate = (bool)queriedEntityRecord["msnfp_chargeoncreate"];
                    localContext.TracingService.Trace("Got msnfp_chargeoncreate.");
                }
                else
                {
                    mSNFP_PaymentSchedule.ChargeonCreate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_chargeoncreate.");
                }
                if (queriedEntityRecord.Contains("msnfp_configurationid") && queriedEntityRecord["msnfp_configurationid"] != null)
                {
                    mSNFP_PaymentSchedule.ConfigurationId = ((EntityReference)queriedEntityRecord["msnfp_configurationid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_configurationid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.ConfigurationId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_configurationid.");
                }
                if (queriedEntityRecord.Contains("msnfp_constituentid") && queriedEntityRecord["msnfp_constituentid"] != null)
                {
                    mSNFP_PaymentSchedule.ConstituentId = ((EntityReference)queriedEntityRecord["msnfp_constituentid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_constituentid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.ConstituentId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_constituentid.");
                }
                if (queriedEntityRecord.Contains("msnfp_customerid") && queriedEntityRecord["msnfp_customerid"] != null)
                {
                    mSNFP_PaymentSchedule.CustomerId = ((EntityReference)queriedEntityRecord["msnfp_customerid"]).Id;
                    if (((EntityReference)queriedEntityRecord["msnfp_customerid"]).LogicalName.ToLower() == "contact")
                    {
                        mSNFP_PaymentSchedule.CustomerIdType = 2;
                    }
                    else if (((EntityReference)queriedEntityRecord["msnfp_customerid"]).LogicalName.ToLower() == "account")
                    {
                        mSNFP_PaymentSchedule.CustomerIdType = 1;
                    }
                    localContext.TracingService.Trace("Got msnfp_customerid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.CustomerId     = null;
                    mSNFP_PaymentSchedule.CustomerIdType = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_customerid.");
                }
                if (queriedEntityRecord.Contains("msnfp_bookdate") && queriedEntityRecord["msnfp_bookdate"] != null)
                {
                    mSNFP_PaymentSchedule.BookDate = (DateTime)queriedEntityRecord["msnfp_bookdate"];
                    localContext.TracingService.Trace("Got msnfp_bookdate.");
                }
                else
                {
                    mSNFP_PaymentSchedule.BookDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_bookdate.");
                }
                if (queriedEntityRecord.Contains("msnfp_paymentprocessorid") && queriedEntityRecord["msnfp_paymentprocessorid"] != null)
                {
                    mSNFP_PaymentSchedule.PaymentProcessorId = ((EntityReference)queriedEntityRecord["msnfp_paymentprocessorid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_paymentprocessorid");
                }
                else
                {
                    mSNFP_PaymentSchedule.PaymentProcessorId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_paymentprocessorid");
                }
                if (queriedEntityRecord.Contains("msnfp_ga_deliverycode") && queriedEntityRecord["msnfp_ga_deliverycode"] != null)
                {
                    mSNFP_PaymentSchedule.GaDeliveryCode = ((OptionSetValue)queriedEntityRecord["msnfp_ga_deliverycode"]).Value;
                    localContext.TracingService.Trace("Got msnfp_ga_deliverycode.");
                }
                else
                {
                    mSNFP_PaymentSchedule.GaDeliveryCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_ga_deliverycode.");
                }
                if (queriedEntityRecord.Contains("msnfp_depositdate") && queriedEntityRecord["msnfp_depositdate"] != null)
                {
                    mSNFP_PaymentSchedule.DepositDate = (DateTime)queriedEntityRecord["msnfp_depositdate"];
                    localContext.TracingService.Trace("Got msnfp_depositdate.");
                }
                else
                {
                    mSNFP_PaymentSchedule.DepositDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_depositdate.");
                }
                if (queriedEntityRecord.Contains("msnfp_emailaddress1") && queriedEntityRecord["msnfp_emailaddress1"] != null)
                {
                    mSNFP_PaymentSchedule.EmailAddress1 = (string)queriedEntityRecord["msnfp_emailaddress1"];
                    localContext.TracingService.Trace("Got msnfp_emailaddress1.");
                }
                else
                {
                    mSNFP_PaymentSchedule.EmailAddress1 = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_emailaddress1.");
                }
                if (queriedEntityRecord.Contains("msnfp_eventid") && queriedEntityRecord["msnfp_eventid"] != null)
                {
                    mSNFP_PaymentSchedule.EventId = ((EntityReference)queriedEntityRecord["msnfp_eventid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_eventid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.EventId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_eventid.");
                }
                if (queriedEntityRecord.Contains("msnfp_eventpackageid") && queriedEntityRecord["msnfp_eventpackageid"] != null)
                {
                    mSNFP_PaymentSchedule.EventPackageId = ((EntityReference)queriedEntityRecord["msnfp_eventpackageid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_eventpackageid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.EventPackageId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_eventpackageid.");
                }
                if (queriedEntityRecord.Contains("msnfp_firstname") && queriedEntityRecord["msnfp_firstname"] != null)
                {
                    mSNFP_PaymentSchedule.FirstName = (string)queriedEntityRecord["msnfp_firstname"];
                    localContext.TracingService.Trace("Got msnfp_firstname.");
                }
                else
                {
                    mSNFP_PaymentSchedule.FirstName = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_firstname.");
                }
                if (queriedEntityRecord.Contains("msnfp_giftbatchid") && queriedEntityRecord["msnfp_giftbatchid"] != null)
                {
                    mSNFP_PaymentSchedule.GiftBatchId = ((EntityReference)queriedEntityRecord["msnfp_giftbatchid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_giftbatchid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.GiftBatchId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_giftbatchid.");
                }
                if (queriedEntityRecord.Contains("msnfp_dataentrysource") && queriedEntityRecord["msnfp_dataentrysource"] != null)
                {
                    mSNFP_PaymentSchedule.DataEntrySource = ((OptionSetValue)queriedEntityRecord["msnfp_dataentrysource"]).Value;
                    localContext.TracingService.Trace("Got msnfp_dataentrysource.");
                }
                else
                {
                    mSNFP_PaymentSchedule.DataEntrySource = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_dataentrysource.");
                }
                if (queriedEntityRecord.Contains("msnfp_paymenttypecode") && queriedEntityRecord["msnfp_paymenttypecode"] != null)
                {
                    mSNFP_PaymentSchedule.PaymentTypeCode = ((OptionSetValue)queriedEntityRecord["msnfp_paymenttypecode"]).Value;
                    localContext.TracingService.Trace("Got msnfp_paymenttypecode.");
                }
                else
                {
                    mSNFP_PaymentSchedule.PaymentTypeCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_paymenttypecode.");
                }
                if (queriedEntityRecord.Contains("msnfp_lastname") && queriedEntityRecord["msnfp_lastname"] != null)
                {
                    mSNFP_PaymentSchedule.LastName = (string)queriedEntityRecord["msnfp_lastname"];
                    localContext.TracingService.Trace("Got msnfp_lastname.");
                }
                else
                {
                    mSNFP_PaymentSchedule.LastName = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_lastname.");
                }
                if (queriedEntityRecord.Contains("msnfp_membershipcategoryid") && queriedEntityRecord["msnfp_membershipcategoryid"] != null)
                {
                    mSNFP_PaymentSchedule.MembershipCategoryId = ((EntityReference)queriedEntityRecord["msnfp_membershipcategoryid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_membershipcategoryid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.MembershipCategoryId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_membershipcategoryid.");
                }
                if (queriedEntityRecord.Contains("msnfp_membershipinstanceid") && queriedEntityRecord["msnfp_membershipinstanceid"] != null)
                {
                    mSNFP_PaymentSchedule.MembershipId = ((EntityReference)queriedEntityRecord["msnfp_membershipinstanceid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_membershipinstanceid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.MembershipId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_membershipinstanceid.");
                }
                if (queriedEntityRecord.Contains("msnfp_mobilephone") && queriedEntityRecord["msnfp_mobilephone"] != null)
                {
                    mSNFP_PaymentSchedule.MobilePhone = (string)queriedEntityRecord["msnfp_mobilephone"];
                    localContext.TracingService.Trace("Got msnfp_mobilephone.");
                }
                else
                {
                    mSNFP_PaymentSchedule.MobilePhone = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_mobilephone.");
                }
                if (queriedEntityRecord.Contains("msnfp_organizationname") && queriedEntityRecord["msnfp_organizationname"] != null)
                {
                    mSNFP_PaymentSchedule.OrganizationName = (string)queriedEntityRecord["msnfp_organizationname"];
                    localContext.TracingService.Trace("Got msnfp_organizationname.");
                }
                else
                {
                    mSNFP_PaymentSchedule.OrganizationName = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_organizationname.");
                }
                if (queriedEntityRecord.Contains("msnfp_packageid") && queriedEntityRecord["msnfp_packageid"] != null)
                {
                    mSNFP_PaymentSchedule.PackageId = ((EntityReference)queriedEntityRecord["msnfp_packageid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_packageid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.PackageId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_packageid.");
                }
                if (queriedEntityRecord.Contains("msnfp_taxreceiptid") && queriedEntityRecord["msnfp_taxreceiptid"] != null)
                {
                    mSNFP_PaymentSchedule.TaxReceiptId = ((EntityReference)queriedEntityRecord["msnfp_taxreceiptid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_taxreceiptid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.TaxReceiptId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_taxreceiptid.");
                }
                if (queriedEntityRecord.Contains("msnfp_receiptpreferencecode") && queriedEntityRecord["msnfp_receiptpreferencecode"] != null)
                {
                    mSNFP_PaymentSchedule.ReceiptPreferenceCode = ((OptionSetValue)queriedEntityRecord["msnfp_receiptpreferencecode"]).Value;
                    localContext.TracingService.Trace("Got msnfp_receiptpreferencecode.");
                }
                else
                {
                    mSNFP_PaymentSchedule.ReceiptPreferenceCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_receiptpreferencecode.");
                }
                if (queriedEntityRecord.Contains("msnfp_telephone1") && queriedEntityRecord["msnfp_telephone1"] != null)
                {
                    mSNFP_PaymentSchedule.Telephone1 = (string)queriedEntityRecord["msnfp_telephone1"];
                    localContext.TracingService.Trace("Got msnfp_telephone1.");
                }
                else
                {
                    mSNFP_PaymentSchedule.Telephone1 = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_telephone1.");
                }
                if (queriedEntityRecord.Contains("msnfp_telephone2") && queriedEntityRecord["msnfp_telephone2"] != null)
                {
                    mSNFP_PaymentSchedule.Telephone2 = (string)queriedEntityRecord["msnfp_telephone2"];
                    localContext.TracingService.Trace("Got msnfp_telephone2.");
                }
                else
                {
                    mSNFP_PaymentSchedule.Telephone2 = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_telephone2.");
                }
                if (queriedEntityRecord.Contains("msnfp_dataentryreference") && queriedEntityRecord["msnfp_dataentryreference"] != null)
                {
                    mSNFP_PaymentSchedule.DataEntryReference = (string)queriedEntityRecord["msnfp_dataentryreference"];
                    localContext.TracingService.Trace("Got msnfp_dataentryreference.");
                }
                else
                {
                    mSNFP_PaymentSchedule.DataEntryReference = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_dataentryreference.");
                }
                if (queriedEntityRecord.Contains("msnfp_invoiceidentifier") && queriedEntityRecord["msnfp_invoiceidentifier"] != null)
                {
                    mSNFP_PaymentSchedule.InvoiceIdentifier = (string)queriedEntityRecord["msnfp_invoiceidentifier"];
                    localContext.TracingService.Trace("Got msnfp_invoiceidentifier.");
                }
                else
                {
                    mSNFP_PaymentSchedule.InvoiceIdentifier = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_invoiceidentifier.");
                }
                if (queriedEntityRecord.Contains("msnfp_transactionfraudcode") && queriedEntityRecord["msnfp_transactionfraudcode"] != null)
                {
                    mSNFP_PaymentSchedule.TransactionFraudCode = (string)queriedEntityRecord["msnfp_transactionfraudcode"];
                    localContext.TracingService.Trace("Got msnfp_transactionfraudcode.");
                }
                else
                {
                    mSNFP_PaymentSchedule.TransactionFraudCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_transactionfraudcode.");
                }
                if (queriedEntityRecord.Contains("msnfp_transactionidentifier") && queriedEntityRecord["msnfp_transactionidentifier"] != null)
                {
                    mSNFP_PaymentSchedule.TransactionIdentifier = (string)queriedEntityRecord["msnfp_transactionidentifier"];
                    localContext.TracingService.Trace("Got msnfp_transactionidentifier.");
                }
                else
                {
                    mSNFP_PaymentSchedule.TransactionIdentifier = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_transactionidentifier.");
                }
                if (queriedEntityRecord.Contains("msnfp_transactionresult") && queriedEntityRecord["msnfp_transactionresult"] != null)
                {
                    mSNFP_PaymentSchedule.TransactionResult = (string)queriedEntityRecord["msnfp_transactionresult"];
                    localContext.TracingService.Trace("Got msnfp_transactionresult.");
                }
                else
                {
                    mSNFP_PaymentSchedule.TransactionResult = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_transactionresult.");
                }
                if (queriedEntityRecord.Contains("msnfp_tributecode") && queriedEntityRecord["msnfp_tributecode"] != null)
                {
                    mSNFP_PaymentSchedule.TributeCode = ((OptionSetValue)queriedEntityRecord["msnfp_tributecode"]).Value;
                    localContext.TracingService.Trace("Got msnfp_tributecode.");
                }
                else
                {
                    mSNFP_PaymentSchedule.TributeCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_tributecode.");
                }
                if (queriedEntityRecord.Contains("msnfp_tributeacknowledgement") && queriedEntityRecord["msnfp_tributeacknowledgement"] != null)
                {
                    mSNFP_PaymentSchedule.TributeAcknowledgement = (string)queriedEntityRecord["msnfp_tributeacknowledgement"];
                    localContext.TracingService.Trace("Got msnfp_tributeacknowledgement.");
                }
                else
                {
                    mSNFP_PaymentSchedule.TributeAcknowledgement = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_tributeacknowledgement.");
                }
                if (queriedEntityRecord.Contains("msnfp_tributeid") && queriedEntityRecord["msnfp_tributeid"] != null)
                {
                    mSNFP_PaymentSchedule.TributeId = ((EntityReference)queriedEntityRecord["msnfp_tributeid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_tributeid.");
                }
                else
                {
                    mSNFP_PaymentSchedule.TributeId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_tributeid.");
                }
                if (queriedEntityRecord.Contains("msnfp_tributemessage") && queriedEntityRecord["msnfp_tributemessage"] != null)
                {
                    mSNFP_PaymentSchedule.TributeMessage = (string)queriedEntityRecord["msnfp_tributemessage"];
                    localContext.TracingService.Trace("Got msnfp_tributemessage.");
                }
                else
                {
                    mSNFP_PaymentSchedule.TributeMessage = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_tributemessage.");
                }
                if (queriedEntityRecord.Contains("msnfp_transactiondescription") && queriedEntityRecord["msnfp_transactiondescription"] != null)
                {
                    mSNFP_PaymentSchedule.TransactionDescription = (string)queriedEntityRecord["msnfp_transactiondescription"];
                    localContext.TracingService.Trace("Got msnfp_transactiondescription.");
                }
                else
                {
                    mSNFP_PaymentSchedule.TransactionDescription = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_transactiondescription.");
                }
                if (queriedEntityRecord.Contains("transactioncurrencyid") && queriedEntityRecord["transactioncurrencyid"] != null)
                {
                    mSNFP_PaymentSchedule.TransactionCurrencyId = ((EntityReference)queriedEntityRecord["transactioncurrencyid"]).Id;
                    localContext.TracingService.Trace("Got TransactionCurrencyId.");
                }
                else
                {
                    mSNFP_PaymentSchedule.TransactionCurrencyId = null;
                    localContext.TracingService.Trace("Did NOT find TransactionCurrencyId.");
                }
                if (queriedEntityRecord.Contains("statecode") && queriedEntityRecord["statecode"] != null)
                {
                    mSNFP_PaymentSchedule.StateCode = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                    localContext.TracingService.Trace("Got StateCode");
                }
                else
                {
                    mSNFP_PaymentSchedule.StateCode = null;
                    localContext.TracingService.Trace("Did NOT find StateCode");
                }
                if (queriedEntityRecord.Contains("statuscode") && queriedEntityRecord["statuscode"] != null)
                {
                    mSNFP_PaymentSchedule.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                    localContext.TracingService.Trace("Got StatusCode");
                }
                else
                {
                    mSNFP_PaymentSchedule.StatusCode = null;
                    localContext.TracingService.Trace("Did NOT find StatusCode");
                }
                if (messageName == "Create")
                {
                    mSNFP_PaymentSchedule.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    mSNFP_PaymentSchedule.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                else
                {
                    mSNFP_PaymentSchedule.CreatedOn = null;
                }
                mSNFP_PaymentSchedule.SyncDate = DateTime.UtcNow;
                if (messageName == "Delete")
                {
                    mSNFP_PaymentSchedule.Deleted     = true;
                    mSNFP_PaymentSchedule.DeletedDate = DateTime.UtcNow;
                }
                else
                {
                    mSNFP_PaymentSchedule.Deleted     = false;
                    mSNFP_PaymentSchedule.DeletedDate = null;
                }
                mSNFP_PaymentSchedule.Receipt     = new HashSet <MSNFP_Receipt>();
                mSNFP_PaymentSchedule.Response    = new HashSet <MSNFP_Response>();
                mSNFP_PaymentSchedule.Transaction = new HashSet <MSNFP_Transaction>();
                localContext.TracingService.Trace("JSON object created");
                if (messageName == "Create")
                {
                    text2 = text2 + text + "/Create" + text;
                }
                else if (messageName == "Update" || messageName == "Delete")
                {
                    text2 = text2 + text + "/Update" + text;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_PaymentSchedule));
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_PaymentSchedule);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + text2);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                string str = webAPIClient.UploadString(text2, @string);
                localContext.TracingService.Trace("Got response.");
                localContext.TracingService.Trace("Response: " + str);
            }
            else
            {
                localContext.TracingService.Trace("No API URL or Enable Portal Pages. Exiting workflow.");
            }
        }
        private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, LocalPluginContext localContext, IOrganizationService service, IPluginExecutionContext context)
        {
            localContext.TracingService.Trace("---------Send the Record to Azure---------");
            string messageName = context.MessageName;
            string text        = "MembershipCategory";
            string text2       = Utilities.GetAzureWebAPIURL(service, context);

            localContext.TracingService.Trace("Got API URL: " + text2);
            if (text2 != string.Empty)
            {
                localContext.TracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord["msnfp_membershipcategoryid"].ToString());
                MSNFP_MembershipCategory mSNFP_MembershipCategory = new MSNFP_MembershipCategory();
                mSNFP_MembershipCategory.MembershipCategoryId = (Guid)queriedEntityRecord["msnfp_membershipcategoryid"];
                mSNFP_MembershipCategory.Name = (queriedEntityRecord.Contains("msnfp_name") ? ((string)queriedEntityRecord["msnfp_name"]) : string.Empty);
                localContext.TracingService.Trace("Title: " + mSNFP_MembershipCategory.Name);
                if (queriedEntityRecord.Contains("msnfp_amount_membership") && queriedEntityRecord["msnfp_amount_membership"] != null)
                {
                    mSNFP_MembershipCategory.AmountMembership = ((Money)queriedEntityRecord["msnfp_amount_membership"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount_membership.");
                }
                else
                {
                    mSNFP_MembershipCategory.AmountMembership = default(decimal);
                    localContext.TracingService.Trace("Did NOT find msnfp_amount_membership.");
                }
                if (queriedEntityRecord.Contains("msnfp_amount_tax") && queriedEntityRecord["msnfp_amount_tax"] != null)
                {
                    mSNFP_MembershipCategory.AmountTax = ((Money)queriedEntityRecord["msnfp_amount_tax"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount_tax.");
                }
                else
                {
                    mSNFP_MembershipCategory.AmountTax = default(decimal);
                    localContext.TracingService.Trace("Did NOT find msnfp_amount_tax.");
                }
                if (queriedEntityRecord.Contains("msnfp_amount") && queriedEntityRecord["msnfp_amount"] != null)
                {
                    mSNFP_MembershipCategory.Amount = ((Money)queriedEntityRecord["msnfp_amount"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount.");
                }
                else
                {
                    mSNFP_MembershipCategory.Amount = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_amount.");
                }
                if (queriedEntityRecord.Contains("msnfp_goodwilldate") && queriedEntityRecord["msnfp_goodwilldate"] != null)
                {
                    mSNFP_MembershipCategory.GoodWillDate = (DateTime)queriedEntityRecord["msnfp_goodwilldate"];
                    localContext.TracingService.Trace("Got msnfp_goodwilldate.");
                }
                else
                {
                    mSNFP_MembershipCategory.GoodWillDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_goodwilldate.");
                }
                if (queriedEntityRecord.Contains("msnfp_membershipduration") && queriedEntityRecord["msnfp_membershipduration"] != null)
                {
                    mSNFP_MembershipCategory.MembershipDuration = ((OptionSetValue)queriedEntityRecord["msnfp_membershipduration"]).Value;
                    localContext.TracingService.Trace("Got msnfp_membershipduration.");
                }
                else
                {
                    mSNFP_MembershipCategory.MembershipDuration = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_membershipduration.");
                }
                if (queriedEntityRecord.Contains("msnfp_renewaldate") && queriedEntityRecord["msnfp_renewaldate"] != null)
                {
                    mSNFP_MembershipCategory.RenewalDate = (DateTime)queriedEntityRecord["msnfp_renewaldate"];
                    localContext.TracingService.Trace("Got msnfp_renewaldate.");
                }
                else
                {
                    mSNFP_MembershipCategory.RenewalDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_renewaldate.");
                }
                if (queriedEntityRecord.Contains("transactioncurrencyid") && queriedEntityRecord["transactioncurrencyid"] != null)
                {
                    mSNFP_MembershipCategory.TransactionCurrencyId = ((EntityReference)queriedEntityRecord["transactioncurrencyid"]).Id;
                    localContext.TracingService.Trace("Got transactioncurrencyid.");
                }
                else
                {
                    mSNFP_MembershipCategory.TransactionCurrencyId = null;
                    localContext.TracingService.Trace("Did NOT find transactioncurrencyid.");
                }
                if (queriedEntityRecord.Contains("statecode") && queriedEntityRecord["statecode"] != null)
                {
                    mSNFP_MembershipCategory.StateCode = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                    localContext.TracingService.Trace("Got statecode.");
                }
                else
                {
                    mSNFP_MembershipCategory.StateCode = null;
                    localContext.TracingService.Trace("Did NOT find statecode.");
                }
                if (queriedEntityRecord.Contains("statuscode") && queriedEntityRecord["statuscode"] != null)
                {
                    mSNFP_MembershipCategory.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                    localContext.TracingService.Trace("Got statuscode.");
                }
                else
                {
                    mSNFP_MembershipCategory.StatusCode = null;
                    localContext.TracingService.Trace("Did NOT find statuscode.");
                }
                if (messageName == "Create")
                {
                    mSNFP_MembershipCategory.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    mSNFP_MembershipCategory.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                else
                {
                    mSNFP_MembershipCategory.CreatedOn = null;
                }
                mSNFP_MembershipCategory.SyncDate = DateTime.UtcNow;
                if (messageName == "Delete")
                {
                    mSNFP_MembershipCategory.Deleted     = true;
                    mSNFP_MembershipCategory.DeletedDate = DateTime.UtcNow;
                }
                else
                {
                    mSNFP_MembershipCategory.Deleted     = false;
                    mSNFP_MembershipCategory.DeletedDate = null;
                }
                mSNFP_MembershipCategory.Membership = new HashSet <MSNFP_Membership>();
                localContext.TracingService.Trace("JSON object created");
                if (messageName == "Create")
                {
                    text2 = text2 + text + "/Create" + text;
                }
                else if (messageName == "Update" || messageName == "Delete")
                {
                    text2 = text2 + text + "/Update" + text;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_MembershipCategory));
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_MembershipCategory);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + text2);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                string text3 = webAPIClient.UploadString(text2, @string);
                localContext.TracingService.Trace("Got response.");
                localContext.TracingService.Trace("Response: " + text3);
                Utilities utilities = new Utilities();
                utilities.CheckAPIReturnJSONForErrors(text3, configurationRecord.GetAttributeValue <OptionSetValue>("msnfp_showapierrorresponses"), localContext.TracingService);
            }
            else
            {
                localContext.TracingService.Trace("No API URL or Enable Portal Pages. Exiting plugin.");
            }
        }
        private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, LocalPluginContext localContext, IOrganizationService service, IPluginExecutionContext context)
        {
            localContext.TracingService.Trace("---------Send the Record to Azure---------");
            string messageName = context.MessageName;
            string text        = "GiftAidDeclaration";
            string text2       = Utilities.GetAzureWebAPIURL(service, context);

            localContext.TracingService.Trace("Got API URL: " + text2);
            if (text2 != string.Empty)
            {
                localContext.TracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord["msnfp_giftaiddeclarationid"].ToString());
                MSNFP_GiftAidDeclaration mSNFP_GiftAidDeclaration = new MSNFP_GiftAidDeclaration();
                mSNFP_GiftAidDeclaration.GiftAidDeclarationId = (Guid)queriedEntityRecord["msnfp_giftaiddeclarationid"];
                if (queriedEntityRecord.Contains("msnfp_customerid") && queriedEntityRecord["msnfp_customerid"] != null)
                {
                    mSNFP_GiftAidDeclaration.CustomerId = ((EntityReference)queriedEntityRecord["msnfp_customerid"]).Id;
                    if (((EntityReference)queriedEntityRecord["msnfp_customerid"]).LogicalName.ToLower() == "contact")
                    {
                        mSNFP_GiftAidDeclaration.CustomerIdType = 2;
                    }
                    else if (((EntityReference)queriedEntityRecord["msnfp_customerid"]).LogicalName.ToLower() == "account")
                    {
                        mSNFP_GiftAidDeclaration.CustomerIdType = 1;
                    }
                    localContext.TracingService.Trace("Got msnfp_customerid.");
                }
                else
                {
                    mSNFP_GiftAidDeclaration.CustomerId     = null;
                    mSNFP_GiftAidDeclaration.CustomerIdType = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_customerid.");
                }
                if (queriedEntityRecord.Contains("msnfp_declarationdate") && queriedEntityRecord["msnfp_declarationdate"] != null)
                {
                    mSNFP_GiftAidDeclaration.DeclarationDate = (DateTime)queriedEntityRecord["msnfp_declarationdate"];
                    localContext.TracingService.Trace("Got msnfp_declarationdate.");
                }
                else
                {
                    mSNFP_GiftAidDeclaration.DeclarationDate = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_declarationdate.");
                }
                if (queriedEntityRecord.Contains("msnfp_declarationdelivered") && queriedEntityRecord["msnfp_declarationdelivered"] != null)
                {
                    mSNFP_GiftAidDeclaration.DeclarationDelivered = ((OptionSetValue)queriedEntityRecord["msnfp_declarationdelivered"]).Value;
                    localContext.TracingService.Trace("Got msnfp_declarationdelivered.");
                }
                else
                {
                    mSNFP_GiftAidDeclaration.DeclarationDelivered = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_declarationdelivered.");
                }
                if (queriedEntityRecord.Contains("msnfp_giftaiddeclarationhtml") && queriedEntityRecord["msnfp_giftaiddeclarationhtml"] != null)
                {
                    mSNFP_GiftAidDeclaration.GiftAidDeclarationHtml = (string)queriedEntityRecord["msnfp_giftaiddeclarationhtml"];
                    localContext.TracingService.Trace("Got msnfp_giftaiddeclarationhtml.");
                }
                else
                {
                    mSNFP_GiftAidDeclaration.GiftAidDeclarationHtml = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_giftaiddeclarationhtml.");
                }
                if (queriedEntityRecord.Contains("msnfp_identifier") && queriedEntityRecord["msnfp_identifier"] != null)
                {
                    mSNFP_GiftAidDeclaration.Identifier = (string)queriedEntityRecord["msnfp_identifier"];
                    localContext.TracingService.Trace("Got msnfp_identifier.");
                }
                else
                {
                    mSNFP_GiftAidDeclaration.Identifier = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_identifier.");
                }
                if (queriedEntityRecord.Contains("statecode") && queriedEntityRecord["statecode"] != null)
                {
                    mSNFP_GiftAidDeclaration.StateCode = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                    localContext.TracingService.Trace("Got statecode.");
                }
                else
                {
                    mSNFP_GiftAidDeclaration.StateCode = null;
                    localContext.TracingService.Trace("Did NOT find statecode.");
                }
                if (queriedEntityRecord.Contains("statuscode") && queriedEntityRecord["statuscode"] != null)
                {
                    mSNFP_GiftAidDeclaration.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                    localContext.TracingService.Trace("Got statuscode.");
                }
                else
                {
                    mSNFP_GiftAidDeclaration.StatusCode = null;
                    localContext.TracingService.Trace("Did NOT find statuscode.");
                }
                if (messageName == "Create")
                {
                    mSNFP_GiftAidDeclaration.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    mSNFP_GiftAidDeclaration.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                else
                {
                    mSNFP_GiftAidDeclaration.CreatedOn = null;
                }
                mSNFP_GiftAidDeclaration.SyncDate = DateTime.UtcNow;
                if (messageName == "Delete")
                {
                    mSNFP_GiftAidDeclaration.Deleted     = true;
                    mSNFP_GiftAidDeclaration.DeletedDate = DateTime.UtcNow;
                    localContext.TracingService.Trace("Setting Deleted Date to:" + mSNFP_GiftAidDeclaration.DeletedDate.ToString());
                }
                else
                {
                    mSNFP_GiftAidDeclaration.Deleted     = false;
                    mSNFP_GiftAidDeclaration.DeletedDate = null;
                }
                if (messageName == "Create")
                {
                    mSNFP_GiftAidDeclaration.Updated = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("msnfp_updated") && queriedEntityRecord["msnfp_updated"] != null)
                {
                    mSNFP_GiftAidDeclaration.Updated = (DateTime)queriedEntityRecord["msnfp_updated"];
                }
                else
                {
                    mSNFP_GiftAidDeclaration.Updated = null;
                }
                localContext.TracingService.Trace("JSON object created");
                if (messageName == "Create")
                {
                    text2 = text2 + text + "/Create" + text;
                }
                else if (messageName == "Update" || messageName == "Delete")
                {
                    text2 = text2 + text + "/Update" + text;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_GiftAidDeclaration));
                localContext.TracingService.Trace("Attempt to create JSON via serialization.");
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_GiftAidDeclaration);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + text2);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                string text3 = webAPIClient.UploadString(text2, @string);
                localContext.TracingService.Trace("Got response.");
                localContext.TracingService.Trace("Response: " + text3);
                Utilities utilities = new Utilities();
                utilities.CheckAPIReturnJSONForErrors(text3, configurationRecord.GetAttributeValue <OptionSetValue>("msnfp_showapierrorresponses"), localContext.TracingService);
            }
            else
            {
                localContext.TracingService.Trace("No API URL or Enable Portal Pages. Exiting workflow.");
            }
        }
        protected override void ExecuteCrmPlugin(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }
            IPluginExecutionContext    pluginExecutionContext     = localContext.PluginExecutionContext;
            IOrganizationService       organizationService        = localContext.OrganizationService;
            OrganizationServiceContext organizationServiceContext = new OrganizationServiceContext(organizationService);
            Utilities utilities = new Utilities();

            localContext.TracingService.Trace("Configuration Create.");
            string messageName = pluginExecutionContext.MessageName;
            Entity entity      = null;
            string empty       = string.Empty;

            if (!pluginExecutionContext.InputParameters.Contains("Target") || (!(pluginExecutionContext.InputParameters["Target"] is Entity) && !(pluginExecutionContext.InputParameters["Target"] is EntityReference)))
            {
                return;
            }
            localContext.TracingService.Trace("Triggered By: " + messageName);
            if (messageName == "Create")
            {
                entity = (Entity)pluginExecutionContext.InputParameters["Target"];
            }
            else if (messageName == "Update" || messageName == "Delete")
            {
                entity = organizationService.Retrieve("msnfp_configuration", pluginExecutionContext.PrimaryEntityId, GetColumnSet());
                localContext.TracingService.Trace("Obtained values");
            }
            if (entity == null || (!(messageName == "Create") && !(messageName == "Update") && !(messageName == "Delete")))
            {
                return;
            }
            localContext.TracingService.Trace("Configuration is Primary entity. Plugin Called On: " + messageName);
            MSNFP_Configuration mSNFP_Configuration = new MSNFP_Configuration();

            mSNFP_Configuration.ConfigurationId = (Guid)entity["msnfp_configurationid"];
            mSNFP_Configuration.Identifier      = (entity.Contains("msnfp_identifier") ? ((string)entity["msnfp_identifier"]) : string.Empty);
            localContext.TracingService.Trace("Obtaining JSON Fields to send to API.");
            mSNFP_Configuration.AzureWebApiUrl        = (entity.Contains("msnfp_azure_webapiurl") ? ((string)entity["msnfp_azure_webapiurl"]) : string.Empty);
            mSNFP_Configuration.AddressAuth1          = (entity.Contains("msnfp_addressauth1") ? ((string)entity["msnfp_addressauth1"]) : string.Empty);
            mSNFP_Configuration.AddressAuth2          = (entity.Contains("msnfp_addressauth2") ? ((string)entity["msnfp_addressauth2"]) : string.Empty);
            mSNFP_Configuration.BankRunPregeneratedBy = ((!entity.Contains("msnfp_bankrun_pregeneratedby")) ? 1 : ((int)entity["msnfp_bankrun_pregeneratedby"]));
            mSNFP_Configuration.CharityTitle          = (entity.Contains("msnfp_charitytitle") ? ((string)entity["msnfp_charitytitle"]) : string.Empty);
            mSNFP_Configuration.ScheMaxRetries        = (entity.Contains("msnfp_sche_maxretries") ? ((int)entity["msnfp_sche_maxretries"]) : 0);
            if (entity.Contains("msnfp_sche_recurrencestart"))
            {
                mSNFP_Configuration.ScheRecurrenceStart = ((OptionSetValue)entity["msnfp_sche_recurrencestart"]).Value;
            }
            else
            {
                mSNFP_Configuration.ScheRecurrenceStart = null;
            }
            mSNFP_Configuration.ScheRetryinterval = ((!entity.Contains("msnfp_sche_retryinterval")) ? 1 : ((int)entity["msnfp_sche_retryinterval"]));
            localContext.TracingService.Trace("Get Entity References.");
            if (entity.Contains("msnfp_teamownerid") && entity["msnfp_teamownerid"] != null)
            {
                mSNFP_Configuration.TeamOwnerId = ((EntityReference)entity["msnfp_teamownerid"]).Id;
            }
            else
            {
                mSNFP_Configuration.TeamOwnerId = null;
            }
            if (entity.Contains("msnfp_paymentprocessorid") && entity["msnfp_paymentprocessorid"] != null)
            {
                mSNFP_Configuration.PaymentProcessorId = ((EntityReference)entity["msnfp_paymentprocessorid"]).Id;
            }
            else
            {
                mSNFP_Configuration.PaymentProcessorId = null;
            }
            if (entity.Contains("msnfp_defaultconfiguration") && entity["msnfp_defaultconfiguration"] != null)
            {
                mSNFP_Configuration.DefaultConfiguration = (bool)entity["msnfp_defaultconfiguration"];
                localContext.TracingService.Trace("Got Default Configuration.");
            }
            else
            {
                mSNFP_Configuration.DefaultConfiguration = null;
                localContext.TracingService.Trace("Did NOT find Default Configuration.");
            }
            if (entity.Contains("statecode") && entity["statecode"] != null)
            {
                mSNFP_Configuration.StateCode = ((OptionSetValue)entity["statecode"]).Value;
                localContext.TracingService.Trace("Got statecode.");
            }
            else
            {
                mSNFP_Configuration.StateCode = null;
                localContext.TracingService.Trace("Did NOT find statecode.");
            }
            if (entity.Contains("statuscode") && entity["statuscode"] != null)
            {
                mSNFP_Configuration.StatusCode = ((OptionSetValue)entity["statuscode"]).Value;
                localContext.TracingService.Trace("Got statuscode.");
            }
            else
            {
                mSNFP_Configuration.StatusCode = null;
                localContext.TracingService.Trace("Did NOT find statuscode.");
            }
            localContext.TracingService.Trace("Set remaining JSON fields to null as they are not used here.");
            if (messageName == "Create")
            {
                mSNFP_Configuration.CreatedOn = DateTime.UtcNow;
            }
            else if (entity.Contains("createdon") && entity["createdon"] != null)
            {
                mSNFP_Configuration.CreatedOn = (DateTime)entity["createdon"];
            }
            else
            {
                mSNFP_Configuration.CreatedOn = null;
            }
            mSNFP_Configuration.SyncDate = DateTime.UtcNow;
            if (messageName == "Delete")
            {
                mSNFP_Configuration.Deleted     = true;
                mSNFP_Configuration.DeletedDate = DateTime.UtcNow;
            }
            else
            {
                mSNFP_Configuration.Deleted     = false;
                mSNFP_Configuration.DeletedDate = null;
            }
            mSNFP_Configuration.PaymentProcessor = null;
            mSNFP_Configuration.Event            = new HashSet <MSNFP_Event>();
            mSNFP_Configuration.EventPackage     = new HashSet <MSNFP_EventPackage>();
            mSNFP_Configuration.PaymentSchedule  = new HashSet <MSNFP_PaymentSchedule>();
            mSNFP_Configuration.ReceiptStack     = new HashSet <MSNFP_ReceiptStack>();
            mSNFP_Configuration.Transaction      = new HashSet <MSNFP_Transaction>();
            localContext.TracingService.Trace("Gathered fields.");
            empty = mSNFP_Configuration.AzureWebApiUrl;
            localContext.TracingService.Trace("API URL: " + empty);
            if (empty.Length > 0)
            {
                localContext.TracingService.Trace("Syncing data to Azure.");
                if (messageName == "Update" || messageName == "Delete")
                {
                    empty += "Configuration/UpdateConfiguration";
                }
                else if (messageName == "Create")
                {
                    empty += "Configuration/CreateConfiguration";
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_Configuration));
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_Configuration);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string @string = Encoding.UTF8.GetString(array, 0, array.Length);
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + empty);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                if (entity.Contains("msnfp_apipadlocktoken"))
                {
                    if ((string)entity["msnfp_apipadlocktoken"] == null)
                    {
                        return;
                    }
                    webAPIClient.Headers["Padlock"] = (string)entity["msnfp_apipadlocktoken"];
                    webAPIClient.Encoding           = Encoding.UTF8;
                    string text = webAPIClient.UploadString(empty, @string);
                    localContext.TracingService.Trace("Got response.");
                    localContext.TracingService.Trace("Response: " + text);
                    Utilities utilities2 = new Utilities();
                    utilities2.CheckAPIReturnJSONForErrors(text, entity.GetAttributeValue <OptionSetValue>("msnfp_showapierrorresponses"), localContext.TracingService);
                    EntityCollection entityCollection = organizationService.RetrieveMultiple(new QueryExpression
                    {
                        EntityName = "transactioncurrency",
                        ColumnSet  = new ColumnSet("transactioncurrencyid")
                    });
                    foreach (Entity entity2 in entityCollection.Entities)
                    {
                        OrganizationRequest organizationRequest = new OrganizationRequest("msnfp_ActionSyncCurrency");
                        organizationRequest["Target"] = entity2.ToEntityReference();
                        organizationService.Execute(organizationRequest);
                        localContext.TracingService.Trace($"currency {entity2.Id} updated.");
                    }
                }
                else
                {
                    localContext.TracingService.Trace("No padlock found, did not send data to Azure.");
                }
            }
            else
            {
                localContext.TracingService.Trace("API URL is null or Portal Syncing is turned off. Exiting Plugin.");
            }
        }
        private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, LocalPluginContext localContext, IOrganizationService service, IPluginExecutionContext context)
        {
            localContext.TracingService.Trace("---------Send the Record to Azure---------");
            string messageName = context.MessageName;
            string text        = "Event";
            string text2       = Utilities.GetAzureWebAPIURL(service, context);

            localContext.TracingService.Trace("Got API URL: " + text2);
            if (text2 != string.Empty)
            {
                localContext.TracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord["msnfp_eventid"].ToString());
                MSNFP_Event mSNFP_Event = new MSNFP_Event
                {
                    EventId = (Guid)queriedEntityRecord["msnfp_eventid"]
                };
                localContext.TracingService.Trace("Got myHttpWebResponse: -1");
                if (queriedEntityRecord.Contains("msnfp_goal") && queriedEntityRecord["msnfp_goal"] != null)
                {
                    mSNFP_Event.Goal = ((Money)queriedEntityRecord["msnfp_goal"]).Value;
                    localContext.TracingService.Trace("Got msnfp_goal");
                }
                else
                {
                    mSNFP_Event.Goal = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_goal.");
                }
                if (queriedEntityRecord.Contains("msnfp_capacity") && queriedEntityRecord["msnfp_capacity"] != null)
                {
                    mSNFP_Event.Capacity = (int)queriedEntityRecord["msnfp_capacity"];
                    localContext.TracingService.Trace("Got msnfp_capacity");
                }
                else
                {
                    mSNFP_Event.Capacity = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_capacity.");
                }
                if (queriedEntityRecord.Contains("msnfp_description") && queriedEntityRecord["msnfp_description"] != null)
                {
                    mSNFP_Event.Description = (string)queriedEntityRecord["msnfp_description"];
                    localContext.TracingService.Trace("Got msnfp_description");
                }
                else
                {
                    mSNFP_Event.Description = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_description.");
                }
                if (queriedEntityRecord.Contains("msnfp_name") && queriedEntityRecord["msnfp_name"] != null)
                {
                    mSNFP_Event.Name = (string)queriedEntityRecord["msnfp_name"];
                    localContext.TracingService.Trace("Got msnfp_name");
                }
                else
                {
                    mSNFP_Event.Name = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_name.");
                }
                if (queriedEntityRecord.Contains("msnfp_amount") && queriedEntityRecord["msnfp_amount"] != null)
                {
                    mSNFP_Event.Amount = ((Money)queriedEntityRecord["msnfp_amount"]).Value;
                    localContext.TracingService.Trace("Got msnfp_amount");
                }
                else
                {
                    mSNFP_Event.Amount = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_amount.");
                }
                if (queriedEntityRecord.Contains("msnfp_eventtypecode") && queriedEntityRecord["msnfp_eventtypecode"] != null)
                {
                    mSNFP_Event.EventTypeCode = ((OptionSetValue)queriedEntityRecord["msnfp_eventtypecode"]).Value;
                    localContext.TracingService.Trace("Got msnfp_eventtypecode");
                }
                else
                {
                    mSNFP_Event.EventTypeCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_eventtypecode.");
                }
                if (queriedEntityRecord.Contains("msnfp_identifier") && queriedEntityRecord["msnfp_identifier"] != null)
                {
                    mSNFP_Event.Identifier = (string)queriedEntityRecord["msnfp_identifier"];
                    localContext.TracingService.Trace("Got msnfp_identifier");
                }
                else
                {
                    mSNFP_Event.Identifier = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_identifier.");
                }
                if (queriedEntityRecord.Contains("msnfp_map_line1") && queriedEntityRecord["msnfp_map_line1"] != null)
                {
                    mSNFP_Event.MapLine1 = (string)queriedEntityRecord["msnfp_map_line1"];
                    localContext.TracingService.Trace("Got msnfp_map_line1");
                }
                else
                {
                    mSNFP_Event.MapLine1 = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_map_line1.");
                }
                if (queriedEntityRecord.Contains("msnfp_map_line2") && queriedEntityRecord["msnfp_map_line2"] != null)
                {
                    mSNFP_Event.MapLine2 = (string)queriedEntityRecord["msnfp_map_line2"];
                    localContext.TracingService.Trace("Got msnfp_map_line2");
                }
                else
                {
                    mSNFP_Event.MapLine2 = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_map_line2.");
                }
                if (queriedEntityRecord.Contains("msnfp_map_line3") && queriedEntityRecord["msnfp_map_line3"] != null)
                {
                    mSNFP_Event.MapLine3 = (string)queriedEntityRecord["msnfp_map_line3"];
                    localContext.TracingService.Trace("Got msnfp_map_line3");
                }
                else
                {
                    mSNFP_Event.MapLine3 = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_map_line3.");
                }
                if (queriedEntityRecord.Contains("msnfp_map_city") && queriedEntityRecord["msnfp_map_city"] != null)
                {
                    mSNFP_Event.MapCity = (string)queriedEntityRecord["msnfp_map_city"];
                    localContext.TracingService.Trace("Got msnfp_map_city");
                }
                else
                {
                    mSNFP_Event.MapCity = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_map_city.");
                }
                if (queriedEntityRecord.Contains("msnfp_stateorprovince") && queriedEntityRecord["msnfp_stateorprovince"] != null)
                {
                    mSNFP_Event.MapStateOrProvince = (string)queriedEntityRecord["msnfp_stateorprovince"];
                    localContext.TracingService.Trace("Got msnfp_stateorprovince");
                }
                else
                {
                    mSNFP_Event.MapStateOrProvince = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_stateorprovince.");
                }
                if (queriedEntityRecord.Contains("msnfp_map_postalcode") && queriedEntityRecord["msnfp_map_postalcode"] != null)
                {
                    mSNFP_Event.MapPostalCode = (string)queriedEntityRecord["msnfp_map_postalcode"];
                    localContext.TracingService.Trace("Got msnfp_map_postalcode");
                }
                else
                {
                    mSNFP_Event.MapPostalCode = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_map_postalcode.");
                }
                if (queriedEntityRecord.Contains("msnfp_map_country") && queriedEntityRecord["msnfp_map_country"] != null)
                {
                    mSNFP_Event.MapCountry = (string)queriedEntityRecord["msnfp_map_country"];
                    localContext.TracingService.Trace("Got msnfp_map_country");
                }
                else
                {
                    mSNFP_Event.MapCountry = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_map_country.");
                }
                if (queriedEntityRecord.Contains("msnfp_proposedend") && queriedEntityRecord["msnfp_proposedend"] != null)
                {
                    mSNFP_Event.ProposedEnd = (DateTime)queriedEntityRecord["msnfp_proposedend"];
                    localContext.TracingService.Trace("Got msnfp_proposedend");
                }
                else
                {
                    mSNFP_Event.ProposedEnd = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_proposedend.");
                }
                if (queriedEntityRecord.Contains("msnfp_proposedstart") && queriedEntityRecord["msnfp_proposedstart"] != null)
                {
                    mSNFP_Event.ProposedStart = (DateTime)queriedEntityRecord["msnfp_proposedstart"];
                    localContext.TracingService.Trace("Got msnfp_proposedstart");
                }
                else
                {
                    mSNFP_Event.ProposedStart = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_proposedstart.");
                }
                if (queriedEntityRecord.Contains("msnfp_campaignid") && queriedEntityRecord["msnfp_campaignid"] != null)
                {
                    mSNFP_Event.CampaignId = ((EntityReference)queriedEntityRecord["msnfp_campaignid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_campaignid");
                }
                else
                {
                    mSNFP_Event.CampaignId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_campaignid.");
                }
                if (queriedEntityRecord.Contains("msnfp_appealid") && queriedEntityRecord["msnfp_appealid"] != null)
                {
                    mSNFP_Event.AppealId = ((EntityReference)queriedEntityRecord["msnfp_appealid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_appealid");
                }
                else
                {
                    mSNFP_Event.AppealId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_appealid.");
                }
                if (queriedEntityRecord.Contains("msnfp_packageid") && queriedEntityRecord["msnfp_packageid"] != null)
                {
                    mSNFP_Event.PackageId = ((EntityReference)queriedEntityRecord["msnfp_packageid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_packageid");
                }
                else
                {
                    mSNFP_Event.PackageId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_packageid.");
                }
                if (queriedEntityRecord.Contains("msnfp_designationid") && queriedEntityRecord["msnfp_designationid"] != null)
                {
                    mSNFP_Event.DesignationId = ((EntityReference)queriedEntityRecord["msnfp_designationid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_designationid");
                }
                else
                {
                    mSNFP_Event.DesignationId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_designationid.");
                }
                if (queriedEntityRecord.Contains("msnfp_configurationid") && queriedEntityRecord["msnfp_configurationid"] != null)
                {
                    mSNFP_Event.ConfigurationId = ((EntityReference)queriedEntityRecord["msnfp_configurationid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_configurationid");
                }
                else
                {
                    mSNFP_Event.ConfigurationId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_configurationid.");
                }
                if (queriedEntityRecord.Contains("msnfp_venueid") && queriedEntityRecord["msnfp_venueid"] != null)
                {
                    mSNFP_Event.VenueId = ((EntityReference)queriedEntityRecord["msnfp_venueid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_venueid");
                }
                else
                {
                    mSNFP_Event.VenueId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_venueid.");
                }
                if (queriedEntityRecord.Contains("transactioncurrencyid") && queriedEntityRecord["transactioncurrencyid"] != null)
                {
                    mSNFP_Event.TransactionCurrencyId = ((EntityReference)queriedEntityRecord["transactioncurrencyid"]).Id;
                    localContext.TracingService.Trace("Got transactioncurrencyid.");
                }
                else
                {
                    mSNFP_Event.TransactionCurrencyId = null;
                    localContext.TracingService.Trace("Did NOT find transactioncurrencyid.");
                }
                if (queriedEntityRecord.Contains("statecode") && queriedEntityRecord["statecode"] != null)
                {
                    mSNFP_Event.StateCode = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                    localContext.TracingService.Trace("Got statecode.");
                }
                else
                {
                    mSNFP_Event.StateCode = null;
                    localContext.TracingService.Trace("Did NOT find statecode.");
                }
                if (queriedEntityRecord.Contains("statuscode") && queriedEntityRecord["statuscode"] != null)
                {
                    mSNFP_Event.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                    localContext.TracingService.Trace("Got statuscode.");
                }
                else
                {
                    mSNFP_Event.StatusCode = null;
                    localContext.TracingService.Trace("Did NOT find statuscode.");
                }
                if (messageName == "Create")
                {
                    mSNFP_Event.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    mSNFP_Event.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                else
                {
                    mSNFP_Event.CreatedOn = null;
                }
                mSNFP_Event.SyncDate = DateTime.UtcNow;
                if (messageName == "Delete")
                {
                    mSNFP_Event.Deleted     = true;
                    mSNFP_Event.DeletedDate = DateTime.UtcNow;
                }
                else
                {
                    mSNFP_Event.Deleted     = false;
                    mSNFP_Event.DeletedDate = null;
                }
                localContext.TracingService.Trace("JSON object created");
                if (messageName == "Create")
                {
                    text2 = text2 + text + "/Create" + text;
                }
                else if (messageName == "Update" || messageName == "Delete")
                {
                    text2 = text2 + text + "/Update" + text;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_Event));
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_Event);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + text2);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                string str = webAPIClient.UploadString(text2, @string);
                localContext.TracingService.Trace("Got response.");
                localContext.TracingService.Trace("Response: " + str);
            }
            else
            {
                localContext.TracingService.Trace("No API URL or Enable Portal Pages. Exiting plugin.");
            }
        }
        private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, LocalPluginContext localContext, IOrganizationService service, IPluginExecutionContext context)
        {
            localContext.TracingService.Trace("---------Send the Record to Azure---------");
            string messageName = context.MessageName;
            string text        = "PaymentProcessor";
            string text2       = Utilities.GetAzureWebAPIURL(service, context);

            localContext.TracingService.Trace("Got API URL: " + text2);
            if (text2 != string.Empty)
            {
                localContext.TracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord["msnfp_paymentprocessorid"].ToString());
                MSNFP_PaymentProcessor mSNFP_PaymentProcessor = new MSNFP_PaymentProcessor();
                mSNFP_PaymentProcessor.PaymentProcessorId = (Guid)queriedEntityRecord["msnfp_paymentprocessorid"];
                mSNFP_PaymentProcessor.Name = (queriedEntityRecord.Contains("msnfp_name") ? ((string)queriedEntityRecord["msnfp_name"]) : string.Empty);
                localContext.TracingService.Trace("Title: " + mSNFP_PaymentProcessor.Name);
                if (queriedEntityRecord.Contains("msnfp_apikey") && queriedEntityRecord["msnfp_apikey"] != null)
                {
                    mSNFP_PaymentProcessor.MonerisApiKey = (string)queriedEntityRecord["msnfp_apikey"];
                    localContext.TracingService.Trace("Got msnfp_apikey.");
                }
                else
                {
                    mSNFP_PaymentProcessor.MonerisApiKey = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_apikey.");
                }
                if (queriedEntityRecord.Contains("msnfp_name") && queriedEntityRecord["msnfp_name"] != null)
                {
                    mSNFP_PaymentProcessor.Name = (string)queriedEntityRecord["msnfp_name"];
                    localContext.TracingService.Trace("Got msnfp_name.");
                }
                else
                {
                    mSNFP_PaymentProcessor.Name = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_name.");
                }
                if (queriedEntityRecord.Contains("msnfp_identifier") && queriedEntityRecord["msnfp_identifier"] != null)
                {
                    mSNFP_PaymentProcessor.Identifier = (string)queriedEntityRecord["msnfp_identifier"];
                    localContext.TracingService.Trace("Got msnfp_identifier.");
                }
                else
                {
                    mSNFP_PaymentProcessor.Identifier = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_identifier.");
                }
                if (queriedEntityRecord.Contains("msnfp_paymentgatewaytype") && queriedEntityRecord["msnfp_paymentgatewaytype"] != null)
                {
                    mSNFP_PaymentProcessor.PaymentGatewayType = ((OptionSetValue)queriedEntityRecord["msnfp_paymentgatewaytype"]).Value;
                    localContext.TracingService.Trace("Got msnfp_paymentgatewaytype.");
                }
                else
                {
                    mSNFP_PaymentProcessor.PaymentGatewayType = 844060000;
                    localContext.TracingService.Trace("Did NOT find msnfp_paymentgatewaytype.");
                }
                if (queriedEntityRecord.Contains("msnfp_storeid") && queriedEntityRecord["msnfp_storeid"] != null)
                {
                    mSNFP_PaymentProcessor.MonerisStoreId = (string)queriedEntityRecord["msnfp_storeid"];
                    localContext.TracingService.Trace("Got msnfp_storeid.");
                }
                else
                {
                    mSNFP_PaymentProcessor.MonerisStoreId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_storeid.");
                }
                if (queriedEntityRecord.Contains("msnfp_testmode") && queriedEntityRecord["msnfp_testmode"] != null)
                {
                    mSNFP_PaymentProcessor.MonerisTestMode = (bool)queriedEntityRecord["msnfp_testmode"];
                    localContext.TracingService.Trace("Got msnfp_testmode.");
                }
                else
                {
                    mSNFP_PaymentProcessor.MonerisTestMode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_testmode.");
                }
                if (queriedEntityRecord.Contains("statecode") && queriedEntityRecord["statecode"] != null)
                {
                    mSNFP_PaymentProcessor.StateCode = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                    localContext.TracingService.Trace("Got statecode.");
                }
                else
                {
                    mSNFP_PaymentProcessor.StateCode = null;
                    localContext.TracingService.Trace("Did NOT find statecode.");
                }
                if (queriedEntityRecord.Contains("statuscode") && queriedEntityRecord["statuscode"] != null)
                {
                    mSNFP_PaymentProcessor.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                    localContext.TracingService.Trace("Got statuscode.");
                }
                else
                {
                    mSNFP_PaymentProcessor.StatusCode = null;
                    localContext.TracingService.Trace("Did NOT find statuscode.");
                }
                if (queriedEntityRecord.Contains("msnfp_bankrunfileformat") && queriedEntityRecord["msnfp_bankrunfileformat"] != null)
                {
                    mSNFP_PaymentProcessor.BankRunFileFormat = ((OptionSetValue)queriedEntityRecord["msnfp_bankrunfileformat"]).Value;
                    localContext.TracingService.Trace("Got msnfp_bankrunfileformat.");
                }
                else
                {
                    mSNFP_PaymentProcessor.BankRunFileFormat = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_bankrunfileformat.");
                }
                if (queriedEntityRecord.Contains("msnfp_scotiabankcustomernumber") && queriedEntityRecord["msnfp_scotiabankcustomernumber"] != null)
                {
                    mSNFP_PaymentProcessor.ScotiabankCustomerNumber = (string)queriedEntityRecord["msnfp_scotiabankcustomernumber"];
                    localContext.TracingService.Trace("Got msnfp_scotiabankcustomernumber.");
                }
                else
                {
                    mSNFP_PaymentProcessor.ScotiabankCustomerNumber = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_scotiabankcustomernumber.");
                }
                if (queriedEntityRecord.Contains("msnfp_originatorshortname") && queriedEntityRecord["msnfp_originatorshortname"] != null)
                {
                    mSNFP_PaymentProcessor.OriginatorShortName = (string)queriedEntityRecord["msnfp_originatorshortname"];
                    localContext.TracingService.Trace("Got msnfp_originatorshortname.");
                }
                else
                {
                    mSNFP_PaymentProcessor.OriginatorShortName = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_originatorshortname.");
                }
                if (queriedEntityRecord.Contains("msnfp_originatorlongname") && queriedEntityRecord["msnfp_originatorlongname"] != null)
                {
                    mSNFP_PaymentProcessor.OriginatorLongName = (string)queriedEntityRecord["msnfp_originatorlongname"];
                    localContext.TracingService.Trace("Got msnfp_originatorlongname.");
                }
                else
                {
                    mSNFP_PaymentProcessor.OriginatorLongName = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_originatorlongname.");
                }
                if (queriedEntityRecord.Contains("msnfp_bmooriginatorid") && queriedEntityRecord["msnfp_bmooriginatorid"] != null)
                {
                    mSNFP_PaymentProcessor.BmoOriginatorId = (string)queriedEntityRecord["msnfp_bmooriginatorid"];
                    localContext.TracingService.Trace("Got msnfp_bmooriginatorid.");
                }
                else
                {
                    mSNFP_PaymentProcessor.BmoOriginatorId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_bmooriginatorid.");
                }
                if (queriedEntityRecord.Contains("msnfp_abaremittername") && queriedEntityRecord["msnfp_abaremittername"] != null)
                {
                    mSNFP_PaymentProcessor.AbaRemitterName = (string)queriedEntityRecord["msnfp_abaremittername"];
                    localContext.TracingService.Trace("Got msnfp_abaremittername.");
                }
                else
                {
                    mSNFP_PaymentProcessor.AbaRemitterName = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_bmooriginatorid.");
                }
                if (queriedEntityRecord.Contains("msnfp_abausername") && queriedEntityRecord["msnfp_abausername"] != null)
                {
                    mSNFP_PaymentProcessor.AbaUserName = (string)queriedEntityRecord["msnfp_abausername"];
                    localContext.TracingService.Trace("Got msnfp_abausername.");
                }
                else
                {
                    mSNFP_PaymentProcessor.AbaUserName = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_abausername.");
                }
                if (queriedEntityRecord.Contains("msnfp_abausernumber") && queriedEntityRecord["msnfp_abausernumber"] != null)
                {
                    mSNFP_PaymentProcessor.AbaUserNumber = (string)queriedEntityRecord["msnfp_abausernumber"];
                    localContext.TracingService.Trace("Got msnfp_abausernumber.");
                }
                else
                {
                    mSNFP_PaymentProcessor.AbaUserNumber = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_abausernumber.");
                }
                if (queriedEntityRecord.Contains("msnfp_iatsagentcode") && queriedEntityRecord["msnfp_iatsagentcode"] != null)
                {
                    mSNFP_PaymentProcessor.IatsAgentCode = (string)queriedEntityRecord["msnfp_iatsagentcode"];
                    localContext.TracingService.Trace("Got msnfp_iatsagentcode.");
                }
                else
                {
                    mSNFP_PaymentProcessor.IatsAgentCode = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_iatsagentcode.");
                }
                if (queriedEntityRecord.Contains("msnfp_iatspassword") && queriedEntityRecord["msnfp_iatspassword"] != null)
                {
                    mSNFP_PaymentProcessor.IatsPassword = (string)queriedEntityRecord["msnfp_iatspassword"];
                    localContext.TracingService.Trace("Got msnfp_iatspassword.");
                }
                else
                {
                    mSNFP_PaymentProcessor.IatsPassword = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_iatspassword.");
                }
                if (messageName == "Create")
                {
                    mSNFP_PaymentProcessor.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    mSNFP_PaymentProcessor.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                else
                {
                    mSNFP_PaymentProcessor.CreatedOn = null;
                }
                mSNFP_PaymentProcessor.Updated  = null;
                mSNFP_PaymentProcessor.SyncDate = DateTime.UtcNow;
                if (messageName == "Delete")
                {
                    mSNFP_PaymentProcessor.Deleted     = true;
                    mSNFP_PaymentProcessor.DeletedDate = DateTime.UtcNow;
                }
                else
                {
                    mSNFP_PaymentProcessor.Deleted     = false;
                    mSNFP_PaymentProcessor.DeletedDate = null;
                }
                mSNFP_PaymentProcessor.Configuration = new HashSet <MSNFP_Configuration>();
                mSNFP_PaymentProcessor.PaymentMethod = new HashSet <MSNFP_PaymentMethod>();
                localContext.TracingService.Trace("JSON object created");
                if (messageName == "Create")
                {
                    text2 = text2 + text + "/Create" + text;
                }
                else if (messageName == "Update" || messageName == "Delete")
                {
                    text2 = text2 + text + "/Update" + text;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_PaymentProcessor));
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_PaymentProcessor);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + text2);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                string text3 = webAPIClient.UploadString(text2, @string);
                localContext.TracingService.Trace("Got response.");
                localContext.TracingService.Trace("Response: " + text3);
                Utilities utilities = new Utilities();
                utilities.CheckAPIReturnJSONForErrors(text3, configurationRecord.GetAttributeValue <OptionSetValue>("msnfp_showapierrorresponses"), localContext.TracingService);
            }
            else
            {
                localContext.TracingService.Trace("No API URL or Enable Portal Pages. Exiting workflow.");
            }
        }
        private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, LocalPluginContext localContext, IOrganizationService service, IPluginExecutionContext context)
        {
            localContext.TracingService.Trace("---------Send the Record to Azure---------");
            string messageName = context.MessageName;
            string text        = "TransactionCurrency";
            string text2       = Utilities.GetAzureWebAPIURL(service, context);

            localContext.TracingService.Trace("Got API URL: " + text2);
            if (text2 != string.Empty)
            {
                localContext.TracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord["transactioncurrencyid"].ToString());
                TransactionCurrency transactionCurrency = new TransactionCurrency();
                transactionCurrency.TransactionCurrencyId = (Guid)queriedEntityRecord["transactioncurrencyid"];
                transactionCurrency.CurrencyName          = (queriedEntityRecord.Contains("currencyname") ? ((string)queriedEntityRecord["currencyname"]) : string.Empty);
                localContext.TracingService.Trace("Title: " + transactionCurrency.CurrencyName);
                if (queriedEntityRecord.Contains("currencysymbol") && queriedEntityRecord["currencysymbol"] != null)
                {
                    transactionCurrency.CurrencySymbol = (string)queriedEntityRecord["currencysymbol"];
                    localContext.TracingService.Trace("Got currencysymbol.");
                }
                else
                {
                    transactionCurrency.CurrencySymbol = null;
                    localContext.TracingService.Trace("Did NOT find currencysymbol.");
                }
                if (queriedEntityRecord.Contains("isocurrencycode") && queriedEntityRecord["isocurrencycode"] != null)
                {
                    transactionCurrency.IsoCurrencyCode = (string)queriedEntityRecord["isocurrencycode"];
                    localContext.TracingService.Trace("Got currenisocurrencycodecysymbol.");
                }
                else
                {
                    transactionCurrency.IsoCurrencyCode = null;
                    localContext.TracingService.Trace("Did NOT find isocurrencycode.");
                }
                if (queriedEntityRecord.Contains("statuscode") && queriedEntityRecord["statuscode"] != null)
                {
                    transactionCurrency.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                    localContext.TracingService.Trace("Got statuscode.");
                }
                else
                {
                    transactionCurrency.StatusCode = null;
                    localContext.TracingService.Trace("Did NOT find statuscode.");
                }
                if (queriedEntityRecord.Contains("statecode") && queriedEntityRecord["statecode"] != null)
                {
                    transactionCurrency.StateCode = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                    localContext.TracingService.Trace("Got statecode.");
                }
                else
                {
                    transactionCurrency.StateCode = null;
                    localContext.TracingService.Trace("Did NOT find statecode.");
                }
                if (queriedEntityRecord.Contains("exchangerate") && queriedEntityRecord["exchangerate"] != null)
                {
                    transactionCurrency.ExchangeRate = (decimal)queriedEntityRecord["exchangerate"];
                    localContext.TracingService.Trace("Got exchangerate.");
                }
                else
                {
                    transactionCurrency.ExchangeRate = null;
                    localContext.TracingService.Trace("Did NOT find exchangerate.");
                }
                if (queriedEntityRecord.Contains("organizationid") && queriedEntityRecord["organizationid"] != null)
                {
                    localContext.TracingService.Trace("Querying for base currency = " + ((EntityReference)queriedEntityRecord["organizationid"]).Id.ToString());
                    ColumnSet columnSet = new ColumnSet("basecurrencyid");
                    Entity    entity    = service.Retrieve("organization", ((EntityReference)queriedEntityRecord["organizationid"]).Id, columnSet);
                    Guid      id        = ((EntityReference)entity["basecurrencyid"]).Id;
                    localContext.TracingService.Trace("CurrencyId = " + id.ToString());
                    if (id == (Guid)queriedEntityRecord["transactioncurrencyid"])
                    {
                        transactionCurrency.IsBase = true;
                    }
                    else
                    {
                        transactionCurrency.IsBase = false;
                    }
                    ITracingService tracingService = localContext.TracingService;
                    Guid            guid           = id;
                    tracingService.Trace("Got base currency = " + guid.ToString());
                    localContext.TracingService.Trace("jsonDataObj.IsBase = " + transactionCurrency.IsBase);
                }
                else
                {
                    transactionCurrency.IsBase = null;
                    localContext.TracingService.Trace("Did NOT find isbase.");
                }
                if (messageName == "Create")
                {
                    transactionCurrency.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    transactionCurrency.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                else
                {
                    transactionCurrency.CreatedOn = null;
                }
                transactionCurrency.SyncDate = DateTime.UtcNow;
                if (messageName == "Delete")
                {
                    transactionCurrency.Deleted     = true;
                    transactionCurrency.DeletedDate = DateTime.UtcNow;
                }
                else
                {
                    transactionCurrency.Deleted     = false;
                    transactionCurrency.DeletedDate = null;
                }
                localContext.TracingService.Trace("JSON object created");
                int num;
                switch (messageName)
                {
                case "Create":
                    text2 = text2 + text + "/Create" + text;
                    break;

                default:
                    num = ((messageName == "msnfp_ActionSyncCurrency") ? 1 : 0);
                    goto IL_06e9;

                case "Update":
                case "Delete":
                {
                    num = 1;
                    goto IL_06e9;
                }
IL_06e9:
                    if (num != 0)
                    {
                        text2 = text2 + text + "/Update" + text;
                    }
                    break;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(TransactionCurrency));
                dataContractJsonSerializer.WriteObject(memoryStream, transactionCurrency);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + text2);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                string text3 = webAPIClient.UploadString(text2, @string);
                localContext.TracingService.Trace("Got response.");
                localContext.TracingService.Trace("Response: " + text3);
                Utilities utilities = new Utilities();
                utilities.CheckAPIReturnJSONForErrors(text3, configurationRecord.GetAttributeValue <OptionSetValue>("msnfp_showapierrorresponses"), localContext.TracingService);
            }
            else
            {
                localContext.TracingService.Trace("No API URL or Enable Portal Pages. Exiting workflow.");
            }
        }
예제 #13
0
        private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, LocalPluginContext localContext, IOrganizationService service, IPluginExecutionContext context)
        {
            localContext.TracingService.Trace("---------Send the Record to Azure---------");
            string messageName = context.MessageName;
            string text        = "Registration";
            string text2       = Utilities.GetAzureWebAPIURL(service, context);

            localContext.TracingService.Trace("Got API URL: " + text2);
            if (text2 != string.Empty)
            {
                localContext.TracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord["msnfp_registrationid"].ToString());
                MSNFP_Registration mSNFP_Registration = new MSNFP_Registration();
                mSNFP_Registration.RegistrationId = (Guid)queriedEntityRecord["msnfp_registrationid"];
                if (queriedEntityRecord.Contains("msnfp_firstname") && queriedEntityRecord["msnfp_firstname"] != null)
                {
                    mSNFP_Registration.FirstName = (string)queriedEntityRecord["msnfp_firstname"];
                    localContext.TracingService.Trace("Got msnfp_firstname.");
                }
                else
                {
                    mSNFP_Registration.FirstName = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_firstname.");
                }
                if (queriedEntityRecord.Contains("msnfp_lastname") && queriedEntityRecord["msnfp_lastname"] != null)
                {
                    mSNFP_Registration.LastName = (string)queriedEntityRecord["msnfp_lastname"];
                    localContext.TracingService.Trace("Got msnfp_lastname.");
                }
                else
                {
                    mSNFP_Registration.LastName = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_lastname.");
                }
                if (queriedEntityRecord.Contains("msnfp_email") && queriedEntityRecord["msnfp_email"] != null)
                {
                    mSNFP_Registration.Email = (string)queriedEntityRecord["msnfp_email"];
                    localContext.TracingService.Trace("Got msnfp_email.");
                }
                else
                {
                    mSNFP_Registration.Email = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_email.");
                }
                if (queriedEntityRecord.Contains("msnfp_telephone") && queriedEntityRecord["msnfp_telephone"] != null)
                {
                    mSNFP_Registration.Telephone = (string)queriedEntityRecord["msnfp_telephone"];
                    localContext.TracingService.Trace("Got msnfp_telephone.");
                }
                else
                {
                    mSNFP_Registration.Telephone = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_telephone.");
                }
                if (queriedEntityRecord.Contains("msnfp_address_line1") && queriedEntityRecord["msnfp_address_line1"] != null)
                {
                    mSNFP_Registration.Address_Line1 = (string)queriedEntityRecord["msnfp_address_line1"];
                    localContext.TracingService.Trace("Got msnfp_address_line1.");
                }
                else
                {
                    mSNFP_Registration.Address_Line1 = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_address_line1.");
                }
                if (queriedEntityRecord.Contains("msnfp_address_line2") && queriedEntityRecord["msnfp_address_line2"] != null)
                {
                    mSNFP_Registration.Address_Line2 = (string)queriedEntityRecord["msnfp_address_line2"];
                    localContext.TracingService.Trace("Got msnfp_address_line2.");
                }
                else
                {
                    mSNFP_Registration.Address_Line2 = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_address_line2.");
                }
                if (queriedEntityRecord.Contains("msnfp_address_city") && queriedEntityRecord["msnfp_address_city"] != null)
                {
                    mSNFP_Registration.Address_City = (string)queriedEntityRecord["msnfp_address_city"];
                    localContext.TracingService.Trace("Got msnfp_address_city.");
                }
                else
                {
                    mSNFP_Registration.Address_City = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_address_city.");
                }
                if (queriedEntityRecord.Contains("msnfp_address_province") && queriedEntityRecord["msnfp_address_province"] != null)
                {
                    mSNFP_Registration.Address_Province = (string)queriedEntityRecord["msnfp_address_province"];
                    localContext.TracingService.Trace("Got msnfp_address_province.");
                }
                else
                {
                    mSNFP_Registration.Address_Province = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_address_province.");
                }
                if (queriedEntityRecord.Contains("msnfp_address_postalcode") && queriedEntityRecord["msnfp_address_postalcode"] != null)
                {
                    mSNFP_Registration.Address_PostalCode = (string)queriedEntityRecord["msnfp_address_postalcode"];
                    localContext.TracingService.Trace("Got msnfp_address_postalcode.");
                }
                else
                {
                    mSNFP_Registration.Address_PostalCode = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_address_postalcode.");
                }
                if (queriedEntityRecord.Contains("msnfp_address_country") && queriedEntityRecord["msnfp_address_country"] != null)
                {
                    mSNFP_Registration.Address_Country = (string)queriedEntityRecord["msnfp_address_country"];
                    localContext.TracingService.Trace("Got msnfp_address_country.");
                }
                else
                {
                    mSNFP_Registration.Address_Country = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_address_country.");
                }
                if (queriedEntityRecord.Contains("msnfp_tableid") && queriedEntityRecord["msnfp_tableid"] != null)
                {
                    mSNFP_Registration.TableId = ((EntityReference)queriedEntityRecord["msnfp_tableid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_tableid");
                }
                else
                {
                    mSNFP_Registration.TableId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_tableid.");
                }
                if (queriedEntityRecord.Contains("msnfp_team") && queriedEntityRecord["msnfp_team"] != null)
                {
                    mSNFP_Registration.Team = (string)queriedEntityRecord["msnfp_team"];
                    localContext.TracingService.Trace("Got msnfp_team.");
                }
                else
                {
                    mSNFP_Registration.Team = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_team.");
                }
                if (queriedEntityRecord.Contains("msnfp_customerid") && queriedEntityRecord["msnfp_customerid"] != null)
                {
                    mSNFP_Registration.CustomerId = ((EntityReference)queriedEntityRecord["msnfp_customerid"]).Id;
                    if (((EntityReference)queriedEntityRecord["msnfp_customerid"]).LogicalName.ToLower() == "contact")
                    {
                        mSNFP_Registration.CustomerIdType = 2;
                    }
                    else if (((EntityReference)queriedEntityRecord["msnfp_customerid"]).LogicalName.ToLower() == "account")
                    {
                        mSNFP_Registration.CustomerIdType = 1;
                    }
                    localContext.TracingService.Trace("Got msnfp_customerid");
                }
                else
                {
                    mSNFP_Registration.CustomerId     = null;
                    mSNFP_Registration.CustomerIdType = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_customerid.");
                }
                if (queriedEntityRecord.Contains("msnfp_date") && queriedEntityRecord["msnfp_date"] != null)
                {
                    mSNFP_Registration.Date = (DateTime)queriedEntityRecord["msnfp_date"];
                    localContext.TracingService.Trace("Got msnfp_date.");
                }
                else
                {
                    mSNFP_Registration.Date = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_date.");
                }
                if (queriedEntityRecord.Contains("msnfp_eventid") && queriedEntityRecord["msnfp_eventid"] != null)
                {
                    mSNFP_Registration.EventId = ((EntityReference)queriedEntityRecord["msnfp_eventid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_eventid .");
                }
                else
                {
                    mSNFP_Registration.EventId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_eventid.");
                }
                if (queriedEntityRecord.Contains("msnfp_eventpackageid") && queriedEntityRecord["msnfp_eventpackageid"] != null)
                {
                    mSNFP_Registration.EventPackageId = ((EntityReference)queriedEntityRecord["msnfp_eventpackageid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_eventpackageid.");
                }
                else
                {
                    mSNFP_Registration.EventPackageId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_eventpackageid.");
                }
                if (queriedEntityRecord.Contains("msnfp_ticketid") && queriedEntityRecord["msnfp_ticketid"] != null)
                {
                    mSNFP_Registration.TicketId = ((EntityReference)queriedEntityRecord["msnfp_ticketid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_ticketid.");
                }
                else
                {
                    mSNFP_Registration.TicketId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_ticketid.");
                }
                if (queriedEntityRecord.Contains("msnfp_groupnotes") && queriedEntityRecord["msnfp_groupnotes"] != null)
                {
                    mSNFP_Registration.GroupNotes = (string)queriedEntityRecord["msnfp_groupnotes"];
                    localContext.TracingService.Trace("Got msnfp_groupnotes.");
                }
                else
                {
                    mSNFP_Registration.GroupNotes = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_groupnotes.");
                }
                if (queriedEntityRecord.Contains("msnfp_eventticketid") && queriedEntityRecord["msnfp_eventticketid"] != null)
                {
                    mSNFP_Registration.EventTicketId = ((EntityReference)queriedEntityRecord["msnfp_eventticketid"]).Id;
                    localContext.TracingService.Trace("Got msnfp_eventticketid.");
                }
                else
                {
                    mSNFP_Registration.EventTicketId = null;
                    localContext.TracingService.Trace("Did NOT find msnfp_eventticketid.");
                }
                if (queriedEntityRecord.Contains("msnfp_identifier") && queriedEntityRecord["msnfp_identifier"] != null)
                {
                    mSNFP_Registration.Identifier = (string)queriedEntityRecord["msnfp_identifier"];
                    localContext.TracingService.Trace("Got msnfp_identifier.");
                }
                else
                {
                    mSNFP_Registration.Identifier = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_identifier.");
                }
                if (queriedEntityRecord.Contains("msnfp_emailaddress1") && queriedEntityRecord["msnfp_emailaddress1"] != null)
                {
                    mSNFP_Registration.msnfp_Emailaddress1 = (string)queriedEntityRecord["msnfp_emailaddress1"];
                    localContext.TracingService.Trace("Got msnfp_emailaddress1.");
                }
                else
                {
                    mSNFP_Registration.msnfp_Emailaddress1 = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_emailaddress1.");
                }
                if (queriedEntityRecord.Contains("msnfp_telephone1") && queriedEntityRecord["msnfp_telephone1"] != null)
                {
                    mSNFP_Registration.msnfp_Telephone1 = (string)queriedEntityRecord["msnfp_telephone1"];
                    localContext.TracingService.Trace("Got msnfp_telephone1.");
                }
                else
                {
                    mSNFP_Registration.msnfp_Telephone1 = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_telephone1.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_city") && queriedEntityRecord["msnfp_billing_city"] != null)
                {
                    mSNFP_Registration.msnfp_Billing_City = (string)queriedEntityRecord["msnfp_billing_city"];
                    localContext.TracingService.Trace("Got msnfp_billing_city.");
                }
                else
                {
                    mSNFP_Registration.msnfp_Billing_City = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_city.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_country") && queriedEntityRecord["msnfp_billing_country"] != null)
                {
                    mSNFP_Registration.msnfp_Billing_Country = (string)queriedEntityRecord["msnfp_billing_country"];
                    localContext.TracingService.Trace("Got msnfp_billing_country.");
                }
                else
                {
                    mSNFP_Registration.msnfp_Billing_Country = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_country.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_line1") && queriedEntityRecord["msnfp_billing_line1"] != null)
                {
                    mSNFP_Registration.msnfp_Billing_Line1 = (string)queriedEntityRecord["msnfp_billing_line1"];
                    localContext.TracingService.Trace("Got msnfp_billing_line1.");
                }
                else
                {
                    mSNFP_Registration.msnfp_Billing_Line1 = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_line1.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_line2") && queriedEntityRecord["msnfp_billing_line2"] != null)
                {
                    mSNFP_Registration.msnfp_Billing_Line2 = (string)queriedEntityRecord["msnfp_billing_line2"];
                    localContext.TracingService.Trace("Got msnfp_billing_line2.");
                }
                else
                {
                    mSNFP_Registration.msnfp_Billing_Line2 = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_line2.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_line3") && queriedEntityRecord["msnfp_billing_line3"] != null)
                {
                    mSNFP_Registration.msnfp_Billing_Line3 = (string)queriedEntityRecord["msnfp_billing_line3"];
                    localContext.TracingService.Trace("Got msnfp_billing_line3.");
                }
                else
                {
                    mSNFP_Registration.msnfp_Billing_Line3 = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_line3.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_postalcode") && queriedEntityRecord["msnfp_billing_postalcode"] != null)
                {
                    mSNFP_Registration.msnfp_Billing_Postalcode = (string)queriedEntityRecord["msnfp_billing_postalcode"];
                    localContext.TracingService.Trace("Got msnfp_billing_postalcode.");
                }
                else
                {
                    mSNFP_Registration.msnfp_Billing_Postalcode = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_postalcode.");
                }
                if (queriedEntityRecord.Contains("msnfp_billing_stateorprovince") && queriedEntityRecord["msnfp_billing_stateorprovince"] != null)
                {
                    mSNFP_Registration.msnfp_Billing_StateorProvince = (string)queriedEntityRecord["msnfp_billing_stateorprovince"];
                    localContext.TracingService.Trace("Got msnfp_billing_stateorprovince.");
                }
                else
                {
                    mSNFP_Registration.msnfp_Billing_StateorProvince = string.Empty;
                    localContext.TracingService.Trace("Did NOT find msnfp_billing_stateorprovince.");
                }
                if (queriedEntityRecord.Contains("statecode") && queriedEntityRecord["statecode"] != null)
                {
                    mSNFP_Registration.StateCode = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                    localContext.TracingService.Trace("Got statecode.");
                }
                else
                {
                    mSNFP_Registration.StateCode = null;
                    localContext.TracingService.Trace("Did NOT find statecode.");
                }
                if (queriedEntityRecord.Contains("statuscode") && queriedEntityRecord["statuscode"] != null)
                {
                    mSNFP_Registration.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                    localContext.TracingService.Trace("Got statuscode.");
                }
                else
                {
                    mSNFP_Registration.StatusCode = null;
                    localContext.TracingService.Trace("Did NOT find statuscode.");
                }
                if (messageName == "Create")
                {
                    mSNFP_Registration.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    mSNFP_Registration.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                else
                {
                    mSNFP_Registration.CreatedOn = null;
                }
                mSNFP_Registration.SyncDate = DateTime.UtcNow;
                if (messageName == "Delete")
                {
                    mSNFP_Registration.Deleted     = true;
                    mSNFP_Registration.DeletedDate = DateTime.UtcNow;
                }
                else
                {
                    mSNFP_Registration.Deleted     = false;
                    mSNFP_Registration.DeletedDate = null;
                }
                localContext.TracingService.Trace("JSON object created");
                if (messageName == "Create")
                {
                    text2 = text2 + text + "/Create" + text;
                }
                else if (messageName == "Update" || messageName == "Delete")
                {
                    text2 = text2 + text + "/Update" + text;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_Registration));
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_Registration);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                localContext.TracingService.Trace("---------Preparing JSON---------");
                localContext.TracingService.Trace("Converted to json API URL : " + text2);
                localContext.TracingService.Trace("JSON: " + @string);
                localContext.TracingService.Trace("---------End of Preparing JSON---------");
                localContext.TracingService.Trace("Sending data to Azure.");
                string str = webAPIClient.UploadString(text2, @string);
                localContext.TracingService.Trace("Got response.");
                localContext.TracingService.Trace("Response: " + str);
            }
            else
            {
                localContext.TracingService.Trace("No API URL or Enable Portal Pages. Exiting plugin.");
            }
        }
예제 #14
0
        private void AddOrUpdateThisRecordWithAzure(Entity queriedEntityRecord, Entity configurationRecord, string messageName)
        {
            tracingService.Trace("---------Send the Record to Azure---------");
            string text  = "DonorCommitment";
            string text2 = configurationRecord.GetAttributeValue <string>("msnfp_azure_webapiurl");

            tracingService.Trace("Got API URL: " + text2);
            if (!string.IsNullOrEmpty(text2))
            {
                tracingService.Trace("Getting Latest Info for Record: " + queriedEntityRecord.Id.ToString());
                MSNFP_DonorCommitment mSNFP_DonorCommitment = new MSNFP_DonorCommitment();
                mSNFP_DonorCommitment.DonorCommitmentId = queriedEntityRecord.Id;
                if (queriedEntityRecord.GetAttributeValue <EntityReference>("msnfp_appealid") != null)
                {
                    mSNFP_DonorCommitment.AppealId = queriedEntityRecord.GetAttributeValue <EntityReference>("msnfp_appealid").Id;
                    tracingService.Trace("Got msnfp_appealid.");
                }
                else
                {
                    mSNFP_DonorCommitment.AppealId = null;
                    tracingService.Trace("Did NOT find msnfp_appealid.");
                }
                if (queriedEntityRecord.GetAttributeValue <EntityReference>("msnfp_packageid") != null)
                {
                    mSNFP_DonorCommitment.PackageId = queriedEntityRecord.GetAttributeValue <EntityReference>("msnfp_packageid").Id;
                    tracingService.Trace("Got msnfp_packageid.");
                }
                else
                {
                    mSNFP_DonorCommitment.PackageId = null;
                    tracingService.Trace("Did NOT find msnfp_packageid.");
                }
                if (queriedEntityRecord.GetAttributeValue <EntityReference>("msnfp_commitment_campaignid") != null)
                {
                    mSNFP_DonorCommitment.CampaignId = queriedEntityRecord.GetAttributeValue <EntityReference>("msnfp_commitment_campaignid").Id;
                    tracingService.Trace("Got msnfp_commitment_campaignid.");
                }
                else
                {
                    mSNFP_DonorCommitment.CampaignId = null;
                    tracingService.Trace("Did NOT find msnfp_commitment_campaignid.");
                }
                if (queriedEntityRecord.GetAttributeValue <Money>("msnfp_totalamount") != null)
                {
                    mSNFP_DonorCommitment.TotalAmount = queriedEntityRecord.GetAttributeValue <Money>("msnfp_totalamount").Value;
                    tracingService.Trace("Got msnfp_totalamount.");
                }
                else
                {
                    mSNFP_DonorCommitment.TotalAmount = null;
                    tracingService.Trace("Did NOT find msnfp_totalamount.");
                }
                if (queriedEntityRecord.GetAttributeValue <EntityReference>("msnfp_customerid") != null)
                {
                    mSNFP_DonorCommitment.CustomerId = queriedEntityRecord.GetAttributeValue <EntityReference>("msnfp_customerid").Id;
                    if (queriedEntityRecord.GetAttributeValue <EntityReference>("msnfp_customerid").LogicalName == "contact")
                    {
                        mSNFP_DonorCommitment.CustomerIdType = 2;
                    }
                    else if (queriedEntityRecord.GetAttributeValue <EntityReference>("msnfp_customerid").LogicalName == "account")
                    {
                        mSNFP_DonorCommitment.CustomerIdType = 1;
                    }
                    tracingService.Trace("Got msnfp_customerid.");
                }
                else
                {
                    mSNFP_DonorCommitment.CustomerId     = null;
                    mSNFP_DonorCommitment.CustomerIdType = null;
                    tracingService.Trace("Did NOT find msnfp_customerid.");
                }
                if (queriedEntityRecord.GetAttributeValue <DateTime?>("msnfp_bookdate").HasValue)
                {
                    mSNFP_DonorCommitment.BookDate = queriedEntityRecord.GetAttributeValue <DateTime>("msnfp_bookdate");
                    tracingService.Trace("Got msnfp_bookdate.");
                }
                else
                {
                    mSNFP_DonorCommitment.BookDate = null;
                    tracingService.Trace("Did NOT find msnfp_bookdate.");
                }
                if (queriedEntityRecord.GetAttributeValue <Money>("msnfp_totalamount_balance") != null)
                {
                    mSNFP_DonorCommitment.TotalAmountBalance = queriedEntityRecord.GetAttributeValue <Money>("msnfp_totalamount_balance").Value;
                    tracingService.Trace("Got msnfp_totalamount_balance.");
                }
                else
                {
                    mSNFP_DonorCommitment.TotalAmountBalance = null;
                    tracingService.Trace("Did NOT find msnfp_totalamount_balance.");
                }
                if (messageName == "Create")
                {
                    mSNFP_DonorCommitment.CreatedOn = DateTime.UtcNow;
                }
                else if (queriedEntityRecord.Contains("createdon") && queriedEntityRecord["createdon"] != null)
                {
                    mSNFP_DonorCommitment.CreatedOn = (DateTime)queriedEntityRecord["createdon"];
                }
                mSNFP_DonorCommitment.SyncDate = DateTime.UtcNow;
                if (messageName == "Delete")
                {
                    mSNFP_DonorCommitment.Deleted     = true;
                    mSNFP_DonorCommitment.DeletedDate = DateTime.UtcNow;
                }
                else
                {
                    mSNFP_DonorCommitment.Deleted     = false;
                    mSNFP_DonorCommitment.DeletedDate = null;
                }
                if (queriedEntityRecord.Contains("statecode") && queriedEntityRecord["statecode"] != null)
                {
                    mSNFP_DonorCommitment.StateCode = ((OptionSetValue)queriedEntityRecord["statecode"]).Value;
                    tracingService.Trace("Got statecode.");
                }
                else
                {
                    mSNFP_DonorCommitment.StateCode = null;
                    tracingService.Trace("Did NOT find statecode.");
                }
                if (queriedEntityRecord.Contains("statuscode") && queriedEntityRecord["statuscode"] != null)
                {
                    mSNFP_DonorCommitment.StatusCode = ((OptionSetValue)queriedEntityRecord["statuscode"]).Value;
                    tracingService.Trace("Got statuscode.");
                }
                else
                {
                    mSNFP_DonorCommitment.StatusCode = null;
                    tracingService.Trace("Did NOT find statuscode.");
                }
                tracingService.Trace("JSON object created");
                if (messageName == "Create")
                {
                    text2 = text2 + text + "/Create" + text;
                }
                else if (messageName == "Update" || messageName == "Delete")
                {
                    text2 = text2 + text + "/Update" + text;
                }
                MemoryStream memoryStream = new MemoryStream();
                DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(MSNFP_DonorCommitment));
                dataContractJsonSerializer.WriteObject(memoryStream, mSNFP_DonorCommitment);
                byte[] array = memoryStream.ToArray();
                memoryStream.Close();
                string       @string      = Encoding.UTF8.GetString(array, 0, array.Length);
                WebAPIClient webAPIClient = new WebAPIClient();
                webAPIClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                webAPIClient.Headers["Padlock"] = (string)configurationRecord["msnfp_apipadlocktoken"];
                webAPIClient.Encoding           = Encoding.UTF8;
                tracingService.Trace("---------Preparing JSON---------");
                tracingService.Trace("Converted to json API URL : " + text2);
                tracingService.Trace("JSON: " + @string);
                tracingService.Trace("---------End of Preparing JSON---------");
                tracingService.Trace("Sending data to Azure.");
                string text3 = webAPIClient.UploadString(text2, @string);
                tracingService.Trace("Got response.");
                tracingService.Trace("Response: " + text3);
                Plugins.PaymentProcesses.Utilities utilities = new Plugins.PaymentProcesses.Utilities();
                utilities.CheckAPIReturnJSONForErrors(text3, configurationRecord.GetAttributeValue <OptionSetValue>("msnfp_showapierrorresponses"), tracingService);
            }
            else
            {
                tracingService.Trace("No API URL or Enable Portal Pages. Exiting workflow.");
            }
        }