public static EntityMaintResult AddNewEntityAddress(int ApplicantId, string StreetNo, string Address1, string Address2,
            string Town, string State, string Zip, string County, int AddressType, decimal latitude, decimal longitude, bool DefAddress)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString))
                {
                    connection.Open();

                    using (SqlCommand command = new SqlCommand())
                    {
                        command.Connection = connection;
                        command.CommandType = CommandType.StoredProcedure;
                        command.CommandText = "AddNewEntityAddress";

                        command.Parameters.Add(new SqlParameter("ApplicantId", ApplicantId));

                        command.Parameters.Add(new SqlParameter("StreetNo", StreetNo));
                        command.Parameters.Add(new SqlParameter("Address1", Address1));
                        command.Parameters.Add(new SqlParameter("Address2", Address2));
                        command.Parameters.Add(new SqlParameter("Town", Town));
                        command.Parameters.Add(new SqlParameter("State", State));
                        command.Parameters.Add(new SqlParameter("Zip", Zip));
                        command.Parameters.Add(new SqlParameter("County", County));
                        command.Parameters.Add(new SqlParameter("AddressType", AddressType));
                        command.Parameters.Add(new SqlParameter("latitude", latitude == 0 ? System.Data.SqlTypes.SqlDecimal.Null : latitude));
                        command.Parameters.Add(new SqlParameter("longitude", longitude == 0 ? System.Data.SqlTypes.SqlDecimal.Null : longitude));
                        command.Parameters.Add(new SqlParameter("DefAddress", DefAddress));

                        SqlParameter parmMessage = new SqlParameter("@isDuplicate", SqlDbType.Bit);
                        parmMessage.Direction = ParameterDirection.Output;
                        command.Parameters.Add(parmMessage);

                        SqlParameter parmMessage1 = new SqlParameter("@isActive", SqlDbType.Int);
                        parmMessage1.Direction = ParameterDirection.Output;
                        command.Parameters.Add(parmMessage1);

                        command.ExecuteNonQuery();

                        EntityMaintResult objResult = new EntityMaintResult();

                        objResult.IsDuplicate = DataUtils.GetBool(command.Parameters["@isDuplicate"].Value.ToString());
                        objResult.IsActive = DataUtils.GetBool(command.Parameters["@isActive"].Value.ToString());

                        return objResult;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static EntityMaintResult AddNewEntity(int LkEntityType, int LKEntityType2, string FYend, string Website, string Email, string HomePhone, string WorkPhone, string CellPhone, string Stvendid,
            string ApplicantName, string Fname, string Lname, int Position, string Title, string FarmName, int LkFVEnterpriseType, int AcresInProduction,
            int AcresOwned, int AcresLeased, int AcresLeasedOut, int TotalAcres, bool OutOFBiz, string Notes, string AgEd, int YearsManagingFarm, int? AppRole,
            int Operation)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString))
                {
                    connection.Open();

                    using (SqlCommand command = new SqlCommand())
                    {
                        command.Connection = connection;
                        command.CommandType = CommandType.StoredProcedure;
                        command.CommandText = "AddNewEntity";
                        command.Parameters.Add(new SqlParameter("LkEntityType", LkEntityType));
                        command.Parameters.Add(new SqlParameter("LKEntityType2", LKEntityType2));
                        command.Parameters.Add(new SqlParameter("FYend", FYend));
                        command.Parameters.Add(new SqlParameter("Website", Website));
                        command.Parameters.Add(new SqlParameter("Email", Email));
                        command.Parameters.Add(new SqlParameter("HomePhone", HomePhone));
                        command.Parameters.Add(new SqlParameter("CellPhone", CellPhone));
                        command.Parameters.Add(new SqlParameter("WorkPhone", WorkPhone));
                        command.Parameters.Add(new SqlParameter("Stvendid", Stvendid));
                        command.Parameters.Add(new SqlParameter("ApplicantName", ApplicantName));
                        command.Parameters.Add(new SqlParameter("Fname", Fname));
                        command.Parameters.Add(new SqlParameter("Lname", Lname));
                        command.Parameters.Add(new SqlParameter("Position", Position));
                        command.Parameters.Add(new SqlParameter("Title", Title == "" ? System.Data.SqlTypes.SqlString.Null : Title));

                        command.Parameters.Add(new SqlParameter("FarmName", FarmName));
                        command.Parameters.Add(new SqlParameter("LkFVEnterpriseType", LkFVEnterpriseType));
                        command.Parameters.Add(new SqlParameter("AcresInProduction", AcresInProduction));
                        command.Parameters.Add(new SqlParameter("AcresOwned", AcresOwned));
                        command.Parameters.Add(new SqlParameter("AcresLeased", AcresLeased));
                        command.Parameters.Add(new SqlParameter("AcresLeasedOut", AcresLeasedOut));
                        command.Parameters.Add(new SqlParameter("TotalAcres", TotalAcres));
                        command.Parameters.Add(new SqlParameter("OutOFBiz", OutOFBiz));
                        command.Parameters.Add(new SqlParameter("Notes", Notes));
                        command.Parameters.Add(new SqlParameter("AgEd", AgEd));
                        command.Parameters.Add(new SqlParameter("YearsManagingFarm", YearsManagingFarm));
                        command.Parameters.Add(new SqlParameter("AppRole", AppRole));
                        command.Parameters.Add(new SqlParameter("Operation", Operation));
                        
                        SqlParameter parmMessage = new SqlParameter("@isDuplicate", SqlDbType.Bit);
                        parmMessage.Direction = ParameterDirection.Output;
                        command.Parameters.Add(parmMessage);
                        
                        SqlParameter parmMessage2 = new SqlParameter("@DuplicateId", SqlDbType.Int);
                        parmMessage2.Direction = ParameterDirection.Output;
                        command.Parameters.Add(parmMessage2);

                        SqlParameter parmMessage1 = new SqlParameter("@ApplicantId", SqlDbType.Int);
                        parmMessage1.Direction = ParameterDirection.Output;
                        command.Parameters.Add(parmMessage1);

                        command.CommandTimeout = 60 * 5;

                        command.ExecuteNonQuery();

                        EntityMaintResult ap = new EntityMaintResult();

                        ap.IsDuplicate = DataUtils.GetBool(command.Parameters["@isDuplicate"].Value.ToString());
                        ap.DuplicateId = DataUtils.GetInt(command.Parameters["@DuplicateId"].Value.ToString());
                        ap.ApplicantId = DataUtils.GetInt(command.Parameters["@ApplicantId"].Value.ToString());

                        return ap;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }