Home360Aristotle 360 APIExample Web Application Using the 360 API

93.4. Example Web Application Using the 360 API

Using the Aristotle 360 api, we have developed a sample web application that demonstrates how to search, select, and update individual records within 360, as well as add a new receipt (contribution) record to an individual.  This sample application was developed using ASP.NET 3.5 (C#).

View the sample application 

ASPX code (Individual.aspx):

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Individual.aspx.cs" Inherits="APIDEMO.Individual" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Working with the 360 Individual API</title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="divSearch">
        <table>
            <tr>
                <td>
                    Search:
                </td>
                <td>
                    <asp:TextBox ID="txtSearchString" runat="server"></asp:TextBox>
                </td>
                <td>
                <asp:Button ID="btnSearch" runat="server" Text="Search" 
                        onclick="btnSearch_Click" />
                </td>
            </tr>
      
        </table>
    </div>
    <div id="divResults" runat="server" style="max-height:300px; width:450px; overflow:scroll" >
        
        <asp:DataList ID="dtlIndividual" runat="server"  >
            <ItemTemplate>
                <table style="background-color:#FFFFCC">
                    <tr>
                        <td style="width:50px">
                            <asp:LinkButton runat="server" Text="View" OnCommand="dtlIndividual_SelectedIndexChanged" CommandName="Select" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ind_GUID")%>'></asp:LinkButton>
                        </td>
                        <td style="width:250px">
                           <%# DataBinder.Eval(Container.DataItem, "ind_FirstName")%> &nbsp;
                           <%# DataBinder.Eval(Container.DataItem, "ind_LastName")%>
                        </td>
                        <td style="width:100px">
                           <%# DataBinder.Eval(Container.DataItem, "iad_City")%> 
                        </td>
                        <td style="width:100px">
                           <%# DataBinder.Eval(Container.DataItem, "iad_State")%> 
                        </td>
                        <td style="width:50px">
                           <%# DataBinder.Eval(Container.DataItem, "iad_Zip5")%> 
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:DataList>
        
    </div>
    
    <div id="divDetail" runat="server"  style="max-height:300px; width:450px;display:none" >
        <p>
            <h3>Edit Individual Information:</h3>
        </p>
        <input type="hidden" runat="server" id="hiddenIndividualGUID" />
        <input type="hidden" runat="server" id="hiddenAddressGUID" />
        <table>
            <tr>
                <td align="right" style="width:120px">
                    First Name:
                </td>
                <td align="left">
                    <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
                </td>
            </tr>
            
            <tr>
                <td align="right" style="width:120px">
                    Middle Name:
                </td>
                <td align="left">
                    <asp:TextBox ID="txtMiddleName" runat="server"></asp:TextBox>
                </td>
            </tr>
            
            <tr>
                <td align="right" style="width:120px">
                    Last Name:
                </td>
                <td align="left">
                    <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
                </td>
            </tr>
            
            <tr>
                <td align="right" style="width:120px">
                    Address 1:
                </td>
                <td align="left">
                    <asp:TextBox ID="txtAddress1" runat="server"></asp:TextBox>
                </td>
            </tr>
            
            <tr>
                <td align="right" style="width:120px">
                    City:
                </td>
                <td align="left">
                    <asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
                </td>
            </tr>
            
            <tr>
                <td align="right" style="width:120px">
                    State:
                </td>
                <td align="left">
                    <asp:TextBox ID="txtState" runat="server"></asp:TextBox>
                </td>
            </tr>
            
            <tr>
                <td align="right" style="width:120px">
                    Zip:
                </td>
                <td align="left">
                    <asp:TextBox ID="txtZip" runat="server"></asp:TextBox>
                </td>
            </tr>
            
            
            <tr>
                <td>
                </td>
                <td align="right">
                <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
                </td>
                <label id="lblError" runat="server"></label>
            </tr>
      
        </table>
    </div>
    
    </form>
</body>
</html>

C# code (Individual.aspx.cs):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;

namespace APIDEMO
{
    public partial class Individual : System.Web.UI.Page
    {
        string strUserName = "";
        string strPassword = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            
            strUserName = ConfigurationSettings.AppSettings["UserName"].ToString();
            strPassword = ConfigurationSettings.AppSettings["Password"].ToString(); ;

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            //SHOW RESULTS PANEL:
            divDetail.Style.Add("display", "none");
            divResults.Style.Add("display", "block");

            string strSearch = txtSearchString.Text;

            //CALL GET INDIVIDUAL WEB SERVICE:
            getIndivdiualInfoWS.getIndividualInformationWebService getIndindividual = new getIndivdiualInfoWS.getIndividualInformationWebService();
            DataSet dsResult = getIndindividual.searchKeyword(strSearch, strUserName, strPassword);

            //BIND DATA LIST:
            dtlIndividual.DataSource = dsResult.Tables["std_Individual"];
            dtlIndividual.DataBind();

        }//end of Search button event handler


        protected void dtlIndividual_SelectedIndexChanged(object sender, CommandEventArgs e)
        {
            //SHOW DETAIL PANEL:
            divDetail.Style.Add("display", "block");
            divResults.Style.Add("display", "none");

            //Clear Text Boxes:
            txtFirstName.Text = "";
            txtMiddleName.Text = "";
            txtLastName.Text = "";
            txtAddress1.Text = "";
            txtCity.Text = "";
            txtState.Text = "";
            txtZip.Text = "";
            lblError.InnerHtml = "";

            string strIndividualGUID = e.CommandArgument.ToString();
            hiddenIndividualGUID.Value = strIndividualGUID;

            //CALL GET INDIVIDUAL WEBSERVICE:
            getIndivdiualInfoWS.getIndividualInformationWebService getIndindividual = new getIndivdiualInfoWS.getIndividualInformationWebService();
            DataSet dsResult = getIndindividual.getDetail(strIndividualGUID,strUserName,strPassword);

            //POPULATE INDIVIDUAL DETAIL TEXTBOXES:
            if (dsResult.Tables["std_Individual"] != null && dsResult.Tables["std_Individual"].Rows.Count > 0)
            {
                DataRow drwInd = dsResult.Tables["std_Individual"].Rows[0]; //GETDETAIL SHOULD ALWAYS RETURN Zero or 1 Rows for std_Individual Table
                
                
                txtFirstName.Text  = drwInd["ind_FirstName"].ToString();
                txtMiddleName.Text = drwInd["ind_MiddleName"].ToString();
                txtLastName.Text   = drwInd["ind_LastName"].ToString();

                if (dsResult.Tables["rtb_IndividualAddress"] != null && dsResult.Tables["rtb_IndividualAddress"].Rows.Count > 0)
                {
                    DataRow drwAddr = dsResult.Tables["rtb_IndividualAddress"].Rows[0]; //Individual Address Could Return Multiple Rows. Select 1st for simplcity.
                    hiddenAddressGUID.Value = drwAddr["iad_GUID"].ToString();
                    txtAddress1.Text = drwAddr["iad_Line1"].ToString();
                    txtCity.Text = drwAddr["iad_City"].ToString();
                    txtState.Text = drwAddr["iad_State"].ToString();
                    txtZip.Text = drwAddr["iad_Zip5"].ToString();
                }

            }
         

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            //GET SELECTED INDIVIDUAL:
            string strIndGUID   = hiddenIndividualGUID.Value;
            string strAddrGUID  = hiddenAddressGUID.Value;
            getIndivdiualInfoWS.getIndividualInformationWebService getIndindividual = new getIndivdiualInfoWS.getIndividualInformationWebService();
            DataSet dsResult = getIndindividual.getDetail(strIndGUID, strUserName, strPassword);

            //SET INDIVIDUAL INFO:
            DataRow drwInd = dsResult.Tables["std_Individual"].Rows[0]; 
            drwInd["ind_FirstName"] = txtFirstName.Text;
            drwInd["ind_MiddleName"] = txtMiddleName.Text;
            drwInd["ind_LastName"] = txtLastName.Text;


            //SET INDIVIDUAL ADDRESS INFO:
            if (hiddenAddressGUID.Value.Length > 0)
            {
                //Update Existing Address:
                foreach (DataRow drw in dsResult.Tables["rtb_IndividualAddress"].Rows)
                {
                    if (drw["iad_GUID"].ToString() == hiddenAddressGUID.Value)
                    {
                        drw["iad_Line1"]    = txtAddress1.Text;
                        drw["iad_City"]     = txtCity.Text;
                        drw["iad_State"]    = txtState.Text;
                        drw["iad_Zip5"]     = txtZip.Text;
                    }

                }//end of loop

            }
            else if (txtAddress1.Text.Length > 0)
            {
                //Address did not exist, Create New Address:
                DataRow drwAddr = dsResult.Tables["rtb_IndividualAddress"].NewRow();

                drwAddr["iad_GUID"]     = System.Guid.NewGuid();
                drwAddr["iad_ind_GUID"] = hiddenIndividualGUID.Value;
                drwAddr["iad_Line1"]    = txtAddress1.Text;
                drwAddr["iad_City"]     = txtCity.Text;
                drwAddr["iad_State"]    = txtState.Text;
                drwAddr["iad_Zip5"]     = txtZip.Text;

                drwAddr["iad_iat_GUID"] = getDefaultAddressType();

                drwAddr["iad_Default"]      = true;
                drwAddr["iad_Deleted"]      = false;
                drwAddr["iad_CreatedOn"]    = System.DateTime.Today;
                drwAddr["iad_CreatedBy"]    = System.Guid.NewGuid();

                dsResult.Tables["rtb_IndividualAddress"].Rows.Add(drwAddr);

            }



            //SAVE INDIVIDUAL INFORMATION:
            setIndividualInfoWS.setIndividualInformationWebService setIndividual = new APIDEMO.setIndividualInfoWS.setIndividualInformationWebService();
            DataSet dsReturn = setIndividual.setDetail(dsResult,strUserName,strPassword);

            //IF ERROR, DISPLAY MESSAGE:
            if (dsReturn.Tables["Error"] != null && dsReturn.Tables["Error"].Rows.Count > 0 )
            {
               lblError.InnerHtml = dsReturn.Tables["Error"].Rows[0]["Message"].ToString();
            }
            else
            {
                lblError.InnerHtml = "";

                ScriptManager.RegisterStartupScript(this, this.GetType(), System.Guid.NewGuid().ToString(), "alert('Individual Information has been saved!');", true);

                //HIDE PANELS:
                divDetail.Style.Add("display", "none");
                divResults.Style.Add("display", "none");
            }

        }//end of View button even Handler

        protected void btnAddReceipt_Click(object sender, EventArgs e)
        {
            //JUST A HARD CODED SAMPLE TO SHOW HOW TO ADD RECEIPTS:
                //Always $100 on 01/01/2010

            //Get Return DataSet with Empty Receipt Table
            getTransactionInfoWebService.getTransactionInfoWebService transWS = new getTransactionInfoWebService.getTransactionInfoWebService();
            DataSet dsReturn = transWS.getReceiptDetail(System.Guid.NewGuid().ToString(), hiddenIndividualGUID.Value.ToString(), "INDIVIDUAL", strUserName, strPassword);

            //Create Row for new Receipt:
            DataRow drwNewReceipt = dsReturn.Tables["std_Receipt"].NewRow();

            drwNewReceipt["rcp_GUID"]       = System.Guid.NewGuid();
            drwNewReceipt["rcp_Date"]       = "01/01/2010";
            drwNewReceipt["rcp_Amount"]     = "100.00";


            drwNewReceipt["rcp_Purpose"]    = "";
            drwNewReceipt["rcp_Check_No"]    = "";
            drwNewReceipt["rcp_Note"]       = "";
            drwNewReceipt["rcp_State"]      = "";
            drwNewReceipt["rcp_FecId"]      = "";
            drwNewReceipt["rcp_TransID"]    = "";
            drwNewReceipt["rcp_SourceID"]   = "";
            drwNewReceipt["rcp_ReceivedYear"] = "";

            drwNewReceipt["rcp_Deposited"] = "01/01/2010";
            drwNewReceipt["rcp_Statement"] = "01/01/2010";

            drwNewReceipt["rcp_Reconciled"]     = false;
            drwNewReceipt["rcp_ForceItemize"]   = false;
            drwNewReceipt["rcp_ForceUnItemize"] = false;
            drwNewReceipt["rcp_Locked"]         = false;



            drwNewReceipt["rcp_acc_GUID"]   = getDefaultAccount("Edison Electric Institute");
            drwNewReceipt["rcp_per_GUID"]   = getDefaultValue("std_ElectionPeriod","per");
            drwNewReceipt["rcp_bat_GUID"]   = getDefaultValue("std_Batch", "bat");
            drwNewReceipt["rcp_sou_GUID"]   = getDefaultValue("std_Source", "sou");

            drwNewReceipt["rcp_rcs_GUID"]   = getReceiptSubType("Contribution", "Check");

            drwNewReceipt["rcp_Deleted"]    =  false;
            drwNewReceipt["rcp_CreatedOn"]  = System.DateTime.Now;
            drwNewReceipt["rcp_CreatedBy"]  = System.Guid.NewGuid();


            //Set Receipt Status:
            drwNewReceipt["rst_GUID"]   = getDefaultValue("std_ReceiptStatus","rst");


            //ADD new Receipt to Database:
            dsReturn.Tables["std_Receipt"].Rows.Add(drwNewReceipt);
            setTransactionInfoWebService.setTransactionInfoWebService setTransWS = new APIDEMO.setTransactionInfoWebService.setTransactionInfoWebService();
            DataSet dsSetReturn = setTransWS.setReceiptDetail(dsReturn, strUserName, strPassword);


            //Check For Errors returned by web service:
            if (dsSetReturn.Tables["Error"].Rows.Count > 0)
            {
                string strError = dsSetReturn.Tables["Error"].Rows[0]["Message"].ToString();
                lblError.InnerHtml = strError;
                
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), System.Guid.NewGuid().ToString(), "alert('Receipt for $100 has been added!');", true);
                
            }

        }//end of btnSave_Click method

        private Guid getDefaultValue(string strTableName, string strTablePrefix)
        {
            Guid returnGUID = System.Guid.NewGuid();

            getIndivdiualInfoWS.getIndividualInformationWebService getIndindividual = new getIndivdiualInfoWS.getIndividualInformationWebService();
            DataSet dsResult = getIndindividual.getList(strTableName, strUserName, strPassword);

            foreach (DataRow drw in dsResult.Tables[strTableName].Rows)
            {
                if ((bool)drw[strTablePrefix+"_Default"])
                    returnGUID = (Guid)drw[strTablePrefix+"_GUID"];
            }

            return returnGUID;

        }//end of getDefaultElectionPeriod method

        private Guid getReceiptSubType(string strReceiptType, string strReceiptSubType)
        {
            Guid returnGUID     = System.Guid.NewGuid();
            strReceiptType      = strReceiptType.ToUpper().Trim();
            strReceiptSubType   = strReceiptSubType.ToUpper().Trim();

            getIndivdiualInfoWS.getIndividualInformationWebService getIndindividual = new getIndivdiualInfoWS.getIndividualInformationWebService();
            DataSet dsResult = getIndindividual.getList("std_ReceiptType", strUserName, strPassword);

            //GET GUID FROM the Receipt Type passed in as parameter:
            Guid rctGUID = System.Guid.NewGuid();
            foreach (DataRow drw in dsResult.Tables["std_ReceiptType"].Rows)
            {
                if (drw["rct_Text"].ToString().ToUpper().Trim() == strReceiptType)
                    rctGUID = (Guid)drw["rct_GUID"];    //Save Receipt Type GUID
            }

            //GET GUID FROM the ReceiptSubtype passed and the Receipt Type above:
            dsResult = getIndindividual.getList("std_ReceiptSubType", strUserName, strPassword);

            foreach (DataRow drw in dsResult.Tables["std_ReceiptSubType"].Rows)
            {
                if (drw["rcs_Text"].ToString().ToUpper().Trim() == strReceiptSubType)
                {
                    if (((Guid)drw["rcs_rct_GUID"]) == rctGUID)
                        returnGUID = (Guid)drw["rcs_GUID"];
                }
            }

            return returnGUID;

        }//end of getReceiptSubType

        private Guid getDefaultAccount(string strFilingCommitteeName)
        {
            //Every Filing Committee has multiple accounts but only one default Account

            Guid returnGUID = System.Guid.NewGuid();
            strFilingCommitteeName = strFilingCommitteeName.ToUpper().Trim();

            getIndivdiualInfoWS.getIndividualInformationWebService getIndindividual = new getIndivdiualInfoWS.getIndividualInformationWebService();
            DataSet dsResult = getIndindividual.getList("std_PoliticalCommittee", strUserName, strPassword);

            //GET GUID FROM the Filing Committee passed in as parameter:
            Guid pcmGUID = System.Guid.NewGuid();
            foreach (DataRow drw in dsResult.Tables["std_PoliticalCommittee"].Rows)
            {
                if (drw["pcm_Name"].ToString().ToUpper().Trim() == strFilingCommitteeName)
                    pcmGUID = (Guid)drw["pcm_GUID"];    //Save Committee ID
            }

            //GET Default Account for Filing Committee above:
            dsResult = getIndindividual.getList("std_Account", strUserName, strPassword);
            foreach (DataRow drw in dsResult.Tables["std_Account"].Rows)
            {
                if ((Guid)drw["acc_pcm_GUID"] == pcmGUID)
                {
                    if (((bool)drw["acc_Default"])) //Found Default Account for give Committee:
                        returnGUID = (Guid)drw["acc_GUID"];
                }
            }


            return returnGUID;

        }//getDefaultAccount method


        private Guid getDefaultAddressType()
        {
            Guid returnGUID = System.Guid.NewGuid();

            getIndivdiualInfoWS.getIndividualInformationWebService getIndindividual = new getIndivdiualInfoWS.getIndividualInformationWebService();
            DataSet dsResult = getIndindividual.getList("std_IndividualAddressType", strUserName, strPassword);

            foreach(DataRow drw in dsResult.Tables["std_IndividualAddressType"].Rows)
            {
                if ((bool)drw["iat_Default"])
                    returnGUID = (Guid)drw["iat_GUID"];
            }

            return returnGUID;

        }//end of getDefaultAddressType


    }
}

This page was: Helpful | Not Helpful