public Boolean Terminate(DateTime forTerminationDate)
        {
            Boolean success = false;

            StringBuilder sqlStatement = new StringBuilder();

            Boolean usingTransaction = true;


            try {
                if (Id == 0)
                {
                    throw new ApplicationException("Permission Denied. Address ID not available.");
                }


                ModifiedAccountInfo = new Mercury.Server.Data.AuthorityAccountStamp(application);


                if (application.EnvironmentDatabase.OpenTransactions == 0)
                {
                    usingTransaction = true;

                    base.application.EnvironmentDatabase.BeginTransaction();
                }

                System.Data.SqlClient.SqlCommand insertCommand = application.EnvironmentDatabase.CreateSqlCommand("dal.EntityAddress_Terminate");

                insertCommand.CommandType = System.Data.CommandType.StoredProcedure;


                insertCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@entityAddressId", System.Data.SqlDbType.BigInt));

                insertCommand.Parameters["@entityAddressId"].Value = Id;


                insertCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@terminationDate", System.Data.SqlDbType.DateTime));

                insertCommand.Parameters["@terminationDate"].Value = forTerminationDate;


                insertCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@modifiedAuthorityName", System.Data.SqlDbType.VarChar, 60));

                insertCommand.Parameters["@modifiedAuthorityName"].Value = modifiedAccountInfo.SecurityAuthorityName;

                insertCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@modifiedAccountId", System.Data.SqlDbType.VarChar, 60));

                insertCommand.Parameters["@modifiedAccountId"].Value = modifiedAccountInfo.UserAccountId;

                insertCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@modifiedAccountName", System.Data.SqlDbType.VarChar, 60));

                insertCommand.Parameters["@modifiedAccountName"].Value = modifiedAccountInfo.UserAccountName;


                if (insertCommand.ExecuteNonQuery() != 1)
                {
                    if (application.EnvironmentDatabase.LastException == null)
                    {
                        throw new ApplicationException("Permission Denied. Unable to Terminate Address.");
                    }

                    base.application.SetLastException(base.application.EnvironmentDatabase.LastException);

                    throw base.application.EnvironmentDatabase.LastException;
                }

                success = true;

                if (usingTransaction)
                {
                    base.application.EnvironmentDatabase.CommitTransaction();
                }
            }

            catch (Exception applicationException) {
                success = false;

                if (usingTransaction)
                {
                    base.application.EnvironmentDatabase.RollbackTransaction();
                }

                base.application.SetLastException(applicationException);
            }

            return(success);
        }
        } // MapDataFields (System.Data.DataRow currentRow)

        public override Boolean Save()
        {
            Boolean success = false;

            StringBuilder sqlStatement = new StringBuilder();

            Boolean usingTransaction = true;


            try {
                Dictionary <String, String> validationResponse = Validate();

                if (validationResponse.Count != 0)
                {
                    foreach (String validationKey in validationResponse.Keys)
                    {
                        throw new ApplicationException("Invalid [" + validationKey + "]: " + validationResponse[validationKey]);
                    }
                }

                modifiedAccountInfo = new Data.AuthorityAccountStamp(application.Session);


                if (application.EnvironmentDatabase.OpenTransactions == 0)
                {
                    usingTransaction = true;

                    base.application.EnvironmentDatabase.BeginTransaction();
                }

                // DETERMINE IF THERE ARE ANY OVERLAPPING SEGMENTS

                List <EntityAddress> overlappingAddresses = application.EntityAddressesGetByEntityTypeOverlap(entityId, addressType, effectiveDate, terminationDate, Id);

                if (overlappingAddresses.Count > 1)
                {
                    application.TraceWriteLineError(application.TraceSwitchGeneral, "[EntityAddress.Save] " + "Entity Id: " + entityId.ToString() + ", Address Type: " + addressType.ToString() + ", Effective Date: " + effectiveDate.ToString("MM/dd/yyyy") + ", Termination Date: " + terminationDate.ToString("MM/dd/yyyy"));

                    throw new ApplicationException("Unable to save due to multiple overlapping addresses.");
                }

                if (overlappingAddresses.Count == 1)
                {
                    // TERMINATE OVERLAPPAING SEGMENTS IF POSSIBLE, TERMINATION DATE IS EFFECTIVE DATE -1

                    success = overlappingAddresses[0].Terminate(effectiveDate.AddDays(-1));

                    if (!success)
                    {
                        application.TraceWriteLineError(application.TraceSwitchGeneral, "[EntityAddress.Save] " + "Entity Id: " + entityId.ToString() + ", Address Type: " + addressType.ToString() + ", Effective Date: " + effectiveDate.ToString("MM/dd/yyyy") + ", Termination Date: " + terminationDate.ToString("MM/dd/yyyy"));

                        throw new ApplicationException("Permission Denied. Unable to terminate previous overlapping address.");
                    }
                }


                // ATTEMPT TO SAVE NEW OR UPDATE EXISTING ENTITY ADDRESS

                ModifiedAccountInfo = new Mercury.Server.Data.AuthorityAccountStamp(application);


                System.Data.SqlClient.SqlCommand sqlCommand = application.EnvironmentDatabase.CreateSqlCommand("dal.EntityAddress_InsertUpdate");

                sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;


                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@entityAddressId", System.Data.SqlDbType.BigInt));

                sqlCommand.Parameters["@entityAddressId"].Value = Id;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@entityId", System.Data.SqlDbType.BigInt));

                sqlCommand.Parameters["@entityId"].Value = entityId;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@addressType", System.Data.SqlDbType.Int));

                sqlCommand.Parameters["@addressType"].Value = addressType;


                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@line1", System.Data.SqlDbType.VarChar, 55));

                sqlCommand.Parameters["@line1"].Value = line1;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@line2", System.Data.SqlDbType.VarChar, 55));

                sqlCommand.Parameters["@line2"].Value = line2;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@city", System.Data.SqlDbType.VarChar, 55));

                sqlCommand.Parameters["@city"].Value = city;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@state", System.Data.SqlDbType.VarChar, 55));

                sqlCommand.Parameters["@state"].Value = state;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@zipCode", System.Data.SqlDbType.VarChar, 55));

                sqlCommand.Parameters["@zipCode"].Value = zipCode;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@zipPlus4", System.Data.SqlDbType.VarChar, 55));

                sqlCommand.Parameters["@zipPlus4"].Value = zipPlus4;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@postalCode", System.Data.SqlDbType.VarChar, 55));

                sqlCommand.Parameters["@postalCode"].Value = postalCode;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@county", System.Data.SqlDbType.VarChar, 55));

                sqlCommand.Parameters["@county"].Value = county;


                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@longitude", System.Data.SqlDbType.Decimal));

                sqlCommand.Parameters["@longitude"].Value = longitude;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@latitude", System.Data.SqlDbType.Decimal));

                sqlCommand.Parameters["@latitude"].Value = latitude;


                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@effectiveDate", System.Data.SqlDbType.DateTime));

                sqlCommand.Parameters["@effectiveDate"].Value = effectiveDate;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@terminationDate", System.Data.SqlDbType.DateTime));

                sqlCommand.Parameters["@terminationDate"].Value = terminationDate;


                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@modifiedAuthorityName", System.Data.SqlDbType.VarChar, 60));

                sqlCommand.Parameters["@modifiedAuthorityName"].Value = modifiedAccountInfo.SecurityAuthorityName;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@modifiedAccountId", System.Data.SqlDbType.VarChar, 60));

                sqlCommand.Parameters["@modifiedAccountId"].Value = modifiedAccountInfo.UserAccountId;

                sqlCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@modifiedAccountName", System.Data.SqlDbType.VarChar, 60));

                sqlCommand.Parameters["@modifiedAccountName"].Value = modifiedAccountInfo.UserAccountName;


                if (sqlCommand.ExecuteNonQuery() != 1)
                {
                    if (application.EnvironmentDatabase.LastException == null)
                    {
                        throw new ApplicationException("Permission Denied. Unable to Save Address.");
                    }

                    base.application.SetLastException(base.application.EnvironmentDatabase.LastException);

                    throw base.application.EnvironmentDatabase.LastException;
                }

                SetIdentity();

                success = true;

                if (usingTransaction)
                {
                    base.application.EnvironmentDatabase.CommitTransaction();
                }
            }

            catch (Exception applicationException) {
                success = false;

                if (usingTransaction)
                {
                    base.application.EnvironmentDatabase.RollbackTransaction();
                }

                base.application.SetLastException(applicationException);
            }

            return(success);
        }