/// <summary>
        /// Update by providing a populated data contract
        /// </summary>
        /// <param name="row">The table row data to use</param>
        /// <param name="connection">The SqlConnection to use</param>
        /// <param name="transaction">The SqlTransaction to use</param>
        /// <returns>The number of rows affected.</returns>
        public virtual int Update(ElectionContract row, SqlConnection connection, SqlTransaction transaction)
        {
            var rowCount = 0;

            using (
                var cmd = new SqlCommand("[Data].[Election_Update]", connection)
            {
                CommandType = CommandType.StoredProcedure, Transaction = transaction
            })
            {
                cmd.Parameters.AddRange(new[] {
                    new SqlParameter("@ElectionId", row.ElectionId)
                    ,
                    new SqlParameter("@ContentInspectionId", row.ContentInspectionId)
                    ,
                    new SqlParameter("@ElectionLevelId", row.ElectionLevelId)
                    ,
                    new SqlParameter("@LocationId", row.LocationId)
                    ,
                    new SqlParameter("@VotingDate", row.VotingDate)
                });

                rowCount = cmd.ExecuteNonQuery();
            }


            return(rowCount);
        }
        /// <summary>
        /// Update by providing a populated data row container
        /// </summary>
        /// <param name="row">The table row data to use</param>
        /// <returns>The number of rows affected.</returns>
        public virtual int Update(ElectionContract row)
        {
            var rowCount = 0;

            VotingInfoDb.ConnectThen(x =>
            {
                using (
                    var cmd = new SqlCommand("[Data].[Election_Update]", x)
                {
                    CommandType = CommandType.StoredProcedure,
                    CommandTimeout = DefaultCommandTimeout
                })
                {
                    cmd.Parameters.AddRange(new[] {
                        new SqlParameter("@ElectionId", row.ElectionId)
                        ,
                        new SqlParameter("@ContentInspectionId", row.ContentInspectionId)
                        ,
                        new SqlParameter("@ElectionLevelId", row.ElectionLevelId)
                        ,
                        new SqlParameter("@LocationId", row.LocationId)
                        ,
                        new SqlParameter("@VotingDate", row.VotingDate)
                    });

                    rowCount = cmd.ExecuteNonQuery();
                }
            });


            return(rowCount);
        }
        /// <summary>
        /// Insert by providing a populated data contract
        /// </summary>
        /// <param name="row">The table row data to use</param>
        /// <param name="connection">The SqlConnection to use</param>
        /// <param name="transaction">The SqlTransaction to use</param>
        /// <returns>1, if insert was successful</returns>
        public int Insert(ElectionContract row, SqlConnection connection, SqlTransaction transaction)
        {
            int?result = null;

            using (
                var cmd = new SqlCommand("[Data].[Election_Insert]", connection)
            {
                CommandType = CommandType.StoredProcedure, Transaction = transaction
            })
            {
                cmd.Parameters.AddRange(new[] {
                    new SqlParameter("@ContentInspectionId", row.ContentInspectionId)
                    ,
                    new SqlParameter("@ElectionLevelId", row.ElectionLevelId)
                    ,
                    new SqlParameter("@LocationId", row.LocationId)
                    ,
                    new SqlParameter("@VotingDate", row.VotingDate)
                });

                result         = (int?)cmd.ExecuteScalar();
                row.ElectionId = result;
            }
            return(result != null ? 1 : 0);
        }
        /// <summary>
        /// Insert by providing a populated data row container
        /// </summary>
        /// <param name="row">The table row data to use</param>
        /// <returns>1, if insert was successful</returns>
        public int Insert(ElectionContract row)
        {
            int?result = null;

            VotingInfoDb.ConnectThen(x =>
            {
                using (
                    var cmd = new SqlCommand("[Data].[Election_Insert]", x)
                {
                    CommandType = CommandType.StoredProcedure,
                    CommandTimeout = DefaultCommandTimeout
                })
                {
                    cmd.Parameters.AddRange(new[] {
                        new SqlParameter("@ContentInspectionId", row.ContentInspectionId)
                        ,
                        new SqlParameter("@ElectionLevelId", row.ElectionLevelId)
                        ,
                        new SqlParameter("@LocationId", row.LocationId)
                        ,
                        new SqlParameter("@VotingDate", row.VotingDate)
                    });

                    result         = (int?)cmd.ExecuteScalar();
                    row.ElectionId = result;
                }
            });
            return(result != null ? 1 : 0);
        }
 /// <summary>
 /// Saves the row, either by inserting (when the identity key is null) or by updating (identity key has value).
 /// </summary>
 /// <param name="row">The data to save</param>
 /// <param name="connection">The SqlConnection to use</param>
 /// <param name="transaction">The SqlTransaction to use</param>
 /// <returns>The number of rows affected.</returns>
 public static int SaveNow(ElectionContract row, SqlConnection connection, SqlTransaction transaction)
 {
     if (row.ElectionId == null)
     {
         return(InsertNow(row, connection, transaction));
     }
     else
     {
         return(UpdateNow(row, connection, transaction));
     }
 }
 /// <summary>
 /// Saves the row, either by inserting (when the identity key is null) or by updating (identity key has value).
 /// </summary>
 /// <param name="row">The data to save</param>
 /// <returns>The number of rows affected.</returns>
 public static int SaveNow(ElectionContract row)
 {
     if (row.ElectionId == null)
     {
         return(InsertNow(row));
     }
     else
     {
         return(UpdateNow(row));
     }
 }
        /// <summary>
        /// Saves the row, either by inserting (when the identity key is null) or by updating (identity key has value).
        /// </summary>
        /// <param name="row">The data to save</param>
        /// <param name="connection">The SqlConnection to use</param>
        /// <param name="transaction">The SqlTransaction to use</param>
        /// <returns>The number of rows affected.</returns>
        public virtual int Save(ElectionContract row, SqlConnection connection, SqlTransaction transaction)
        {
            if (row == null)
            {
                return(0);
            }
            if (row.ElectionId != null)
            {
                return(Update(row, connection, transaction));
            }

            return(Insert(row, connection, transaction));
        }
        /// <summary>
        /// Saves the row, either by inserting (when the identity key is null) or by updating (identity key has value).
        /// </summary>
        /// <param name="row">The data to save</param>
        /// <returns>The number of rows affected.</returns>
        public virtual int Save(ElectionContract row)
        {
            if (row == null)
            {
                return(0);
            }
            if (row.ElectionId != null)
            {
                return(Update(row));
            }

            return(Insert(row));
        }
        /// <summary>
        /// Delete by providing a populated data contract
        /// </summary>
        /// <param name="row">The table row data to use</param>
        /// <param name="connection">The SqlConnection to use</param>
        /// <param name="transaction">The SqlTransaction to use</param>
        /// <returns>The number of rows affected.</returns>
        public virtual int Delete(ElectionContract row, SqlConnection connection, SqlTransaction transaction)
        {
            var rowCount = 0;

            using (
                var cmd = new SqlCommand("[Data].[Election_Delete]", connection)
            {
                CommandType = CommandType.StoredProcedure, Transaction = transaction
            })
            {
                cmd.Parameters.AddRange(new[] {
                    new SqlParameter("@ElectionId", row.ElectionId)
                });

                rowCount = cmd.ExecuteNonQuery();
            }


            return(rowCount);
        }
 /// <summary>
 /// Insert by providing a populated data contract
 /// </summary>
 /// <param name="row">The table row data to use</param>
 /// <param name="connection">The SqlConnection to use</param>
 /// <param name="transaction">The SqlTransaction to use</param>
 /// <returns>The number of rows affected.</returns>
 public static int InsertNow(ElectionContract row, SqlConnection connection, SqlTransaction transaction)
 {
     return((new ElectionLogic()).Insert(row, connection, transaction));
 }
 /// <summary>
 /// Insert by providing a populated data row container
 /// </summary>
 /// <param name="row">The table row data to use</param>
 /// <returns>The number of rows affected.</returns>
 public static int InsertNow(ElectionContract row)
 {
     return((new ElectionLogic()).Insert(row));
 }
 /// <summary>
 /// Delete by providing a populated data contract
 /// </summary>
 /// <param name="row">The table row data to use</param>
 /// <param name="connection">The SqlConnection to use</param>
 /// <param name="transaction">The SqlTransaction to use</param>
 /// <returns>The number of rows affected.</returns>
 public static int DeleteNow(ElectionContract row, SqlConnection connection, SqlTransaction transaction)
 {
     return((new ElectionLogic()).Delete(row, connection, transaction));
 }
 /// <summary>
 /// Delete by providing a populated data row container
 /// </summary>
 /// <param name="row">The table row data to use</param>
 /// <returns>The number of rows affected.</returns>
 public static int DeleteNow(ElectionContract row)
 {
     return((new ElectionLogic()).Delete(row));
 }