private VoucherEditDto FetchVoucherEdit(SafeDataReader dr)
        {
            var voucherEdit = new VoucherEditDto();
            // Value properties
            voucherEdit.Id = dr.GetInt32("tran_id");
            voucherEdit.Amount = (Decimal?)dr.GetValue("tran_amount");
            voucherEdit.PersonId = !dr.IsDBNull("person_id") ? dr.GetString("person_id") : null;
            voucherEdit.NamePrefix = !dr.IsDBNull("name_prefix") ? dr.GetString("name_prefix") : null;
            voucherEdit.First = !dr.IsDBNull("first_name") ? dr.GetString("first_name") : null;
            voucherEdit.Middle = !dr.IsDBNull("middle_name") ? dr.GetString("middle_name") : null;
            voucherEdit.Last = !dr.IsDBNull("last_name") ? dr.GetString("last_name") : null;
            voucherEdit.Suffix = !dr.IsDBNull("name_suffix") ? dr.GetString("name_suffix") : null;
            voucherEdit.Title = !dr.IsDBNull("title") ? dr.GetString("title") : null;
            voucherEdit.Company = !dr.IsDBNull("company") ? dr.GetString("company") : null;
            voucherEdit.AddressLine1 = !dr.IsDBNull("address_1") ? dr.GetString("address_1") : null;
            voucherEdit.AddressLine2 = !dr.IsDBNull("address_2") ? dr.GetString("address_2") : null;
            voucherEdit.Municipality = !dr.IsDBNull("municipality") ? dr.GetString("municipality") : null;
            voucherEdit.Region = !dr.IsDBNull("region") ? dr.GetString("region") : null;
            voucherEdit.PostalCode = !dr.IsDBNull("postal_code") ? dr.GetString("postal_code") : null;
            voucherEdit.Country = !dr.IsDBNull("country") ? dr.GetString("country") : null;
            voucherEdit.PhoneNumber = !dr.IsDBNull("phone_number") ? dr.GetString("phone_number") : null;
            voucherEdit.EmailAddress = !dr.IsDBNull("email") ? dr.GetString("email") : null;
            voucherEdit.Updated = !dr.IsDBNull("updated") ? dr.GetSmartDate("updated", true) : null;

            return voucherEdit;
        }
 /// <summary>
 /// Updates in the database all changes made to the VoucherEdit object.
 /// </summary>
 /// <param name="voucherEdit">The Voucher Edit DTO.</param>
 /// <returns>The updated <see cref="VoucherEditDto"/>.</returns>
 public VoucherEditDto Update(VoucherEditDto voucherEdit)
 {
     using (var ctx = ConnectionManager<SqlConnection>.GetManager("CoopCheck"))
     {
         using (var cmd = new SqlCommand("dbo.dal_UpdateVoucher", ctx.Connection))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@tran_id", voucherEdit.Id).DbType = DbType.Int32;
             cmd.Parameters.AddWithValue("@tran_amount", voucherEdit.Amount == null ? (object)DBNull.Value : voucherEdit.Amount.Value).DbType = DbType.Decimal;
             cmd.Parameters.AddWithValue("@person_id", voucherEdit.PersonId == null ? (object)DBNull.Value : voucherEdit.PersonId).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@name_prefix", voucherEdit.NamePrefix == null ? (object)DBNull.Value : voucherEdit.NamePrefix).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@first_name", voucherEdit.First == null ? (object)DBNull.Value : voucherEdit.First).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@middle_name", voucherEdit.Middle == null ? (object)DBNull.Value : voucherEdit.Middle).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@last_name", voucherEdit.Last == null ? (object)DBNull.Value : voucherEdit.Last).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@name_suffix", voucherEdit.Suffix == null ? (object)DBNull.Value : voucherEdit.Suffix).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@title", voucherEdit.Title == null ? (object)DBNull.Value : voucherEdit.Title).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@company", voucherEdit.Company == null ? (object)DBNull.Value : voucherEdit.Company).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@address_1", voucherEdit.AddressLine1 == null ? (object)DBNull.Value : voucherEdit.AddressLine1).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@address_2", voucherEdit.AddressLine2 == null ? (object)DBNull.Value : voucherEdit.AddressLine2).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@municipality", voucherEdit.Municipality == null ? (object)DBNull.Value : voucherEdit.Municipality).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@region", voucherEdit.Region == null ? (object)DBNull.Value : voucherEdit.Region).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@postal_code", voucherEdit.PostalCode == null ? (object)DBNull.Value : voucherEdit.PostalCode).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@country", voucherEdit.Country == null ? (object)DBNull.Value : voucherEdit.Country).DbType = DbType.StringFixedLength;
             cmd.Parameters.AddWithValue("@phone_number", voucherEdit.PhoneNumber == null ? (object)DBNull.Value : voucherEdit.PhoneNumber).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@email", voucherEdit.EmailAddress == null ? (object)DBNull.Value : voucherEdit.EmailAddress).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@updated", voucherEdit.Updated.DBValue).DbType = DbType.DateTime;
             cmd.Parameters.AddWithValue("@usr", Csla.ApplicationContext.User.Identity.Name).DbType = DbType.String;
             var rowsAffected = cmd.ExecuteNonQuery();
             if (rowsAffected == 0)
                 throw new DataNotFoundException("VoucherEdit");
         }
     }
     return voucherEdit;
 }
 public VoucherEditDto Fetch(int id)
 {
     var voucherEdit = new VoucherEditDto();
     using (var ctx = ConnectionManager<SqlConnection>.GetManager("CoopCheck"))
     {
         using (var cmd = new SqlCommand("dbo.dsa_GetVoucher", ctx.Connection))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@tran_id", id).DbType = DbType.Int32;
             var dr = new SafeDataReader(cmd.ExecuteReader());
             dr.Read();
             voucherEdit.Id = dr.GetInt32("tran_id");
             voucherEdit.Amount = (Decimal?)dr.GetValue("tran_amount");
             voucherEdit.PersonId = !dr.IsDBNull("person_id") ? dr.GetString("person_id") : null;
             voucherEdit.NamePrefix = !dr.IsDBNull("name_prefix") ? dr.GetString("name_prefix") : null;
             voucherEdit.First = !dr.IsDBNull("first_name") ? dr.GetString("first_name") : null;
             voucherEdit.Middle = !dr.IsDBNull("middle_name") ? dr.GetString("middle_name") : null;
             voucherEdit.Last = !dr.IsDBNull("last_name") ? dr.GetString("last_name") : null;
             voucherEdit.Suffix = !dr.IsDBNull("name_suffix") ? dr.GetString("name_suffix") : null;
             voucherEdit.Title = !dr.IsDBNull("title") ? dr.GetString("title") : null;
             voucherEdit.Company = !dr.IsDBNull("company") ? dr.GetString("company") : null;
             voucherEdit.AddressLine1 = !dr.IsDBNull("address_1") ? dr.GetString("address_1") : null;
             voucherEdit.AddressLine2 = !dr.IsDBNull("address_2") ? dr.GetString("address_2") : null;
             voucherEdit.Municipality = !dr.IsDBNull("municipality") ? dr.GetString("municipality") : null;
             voucherEdit.Region = !dr.IsDBNull("region") ? dr.GetString("region") : null;
             voucherEdit.PostalCode = !dr.IsDBNull("postal_code") ? dr.GetString("postal_code") : null;
             voucherEdit.Country = !dr.IsDBNull("country") ? dr.GetString("country") : null;
             voucherEdit.PhoneNumber = !dr.IsDBNull("phone_number") ? dr.GetString("phone_number") : null;
             voucherEdit.EmailAddress = !dr.IsDBNull("email") ? dr.GetString("email") : null;
             voucherEdit.Updated = !dr.IsDBNull("updated") ? dr.GetSmartDate("updated", true) : null;
         }
     }
     return voucherEdit;
 }
 /// <summary>
 /// Inserts a new VoucherEdit object in the database.
 /// </summary>
 /// <param name="voucherEdit">The Voucher Edit DTO.</param>
 /// <returns>The new <see cref="VoucherEditDto"/>.</returns>
 public VoucherEditDto Insert(VoucherEditDto voucherEdit)
 {
     using (var ctx = ConnectionManager<SqlConnection>.GetManager("CoopCheck"))
     {
         using (var cmd = new SqlCommand("dbo.dal_AddVoucher", ctx.Connection))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@batch_num", voucherEdit.Parent_Num).DbType = DbType.Int32;
             cmd.Parameters.Add("@tran_id", SqlDbType.Int).Direction = ParameterDirection.Output;
             cmd.Parameters.AddWithValue("@tran_amount", voucherEdit.Amount).DbType = DbType.Decimal;
             cmd.Parameters.AddWithValue("@person_id", voucherEdit.PersonId).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@name_prefix", voucherEdit.NamePrefix).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@first_name", voucherEdit.First).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@middle_name", voucherEdit.Middle).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@last_name", voucherEdit.Last).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@name_suffix", voucherEdit.Suffix).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@title", voucherEdit.Title).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@company", voucherEdit.Company).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@address_1", voucherEdit.AddressLine1).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@address_2", voucherEdit.AddressLine2).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@municipality", voucherEdit.Municipality).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@region", voucherEdit.Region).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@postal_code", voucherEdit.PostalCode).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@country", voucherEdit.Country).DbType = DbType.StringFixedLength;
             cmd.Parameters.AddWithValue("@phone_number", voucherEdit.PhoneNumber).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@email", voucherEdit.EmailAddress).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@usr", Csla.ApplicationContext.User.Identity.Name).DbType =
                 DbType.String;
             cmd.Parameters.Add("@updated", SqlDbType.DateTime).Direction = ParameterDirection.Output;
             cmd.ExecuteNonQuery();
             voucherEdit.Id = (int) cmd.Parameters["@tran_id"].Value;
             voucherEdit.Updated = (DateTime) cmd.Parameters["@updated"].Value;
         }
         return voucherEdit;
     }
 }