/// <summary>
 /// Updates in the database all changes made to the Voucher object.
 /// </summary>
 /// <param name="voucher">The Voucher DTO.</param>
 /// <returns>The updated <see cref="VoucherDto"/>.</returns>
 public VoucherDto Update(VoucherDto voucher)
 {
     using (var ctx = ConnectionManager<SqlConnection>.GetManager("MyDatabase"))
     {
         using (var cmd = new SqlCommand("dbo.UpdateVoucher", ctx.Connection))
         {
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@tran_id", voucher.Id).DbType = DbType.Int32;
             cmd.Parameters.AddWithValue("@tran_amount", voucher.Amount == null ? (object)DBNull.Value : voucher.Amount.Value).DbType = DbType.Decimal;
             cmd.Parameters.AddWithValue("@person_id", voucher.PersonId == null ? (object)DBNull.Value : voucher.PersonId).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@name_prefix", voucher.NamePrefix == null ? (object)DBNull.Value : voucher.NamePrefix).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@first_name", voucher.FirstName == null ? (object)DBNull.Value : voucher.FirstName).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@middle_name", voucher.MiddleName == null ? (object)DBNull.Value : voucher.MiddleName).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@last_name", voucher.LastName == null ? (object)DBNull.Value : voucher.LastName).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@name_suffix", voucher.NameSuffix == null ? (object)DBNull.Value : voucher.NameSuffix).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@title", voucher.Title == null ? (object)DBNull.Value : voucher.Title).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@company", voucher.Company == null ? (object)DBNull.Value : voucher.Company).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@address_1", voucher.AddressLine1 == null ? (object)DBNull.Value : voucher.AddressLine1).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@address_2", voucher.AddressLine2 == null ? (object)DBNull.Value : voucher.AddressLine2).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@municipality", voucher.Municipality == null ? (object)DBNull.Value : voucher.Municipality).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@region", voucher.Region == null ? (object)DBNull.Value : voucher.Region).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@postal_code", voucher.PostalCode == null ? (object)DBNull.Value : voucher.PostalCode).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@country", voucher.Country == null ? (object)DBNull.Value : voucher.Country).DbType = DbType.StringFixedLength;
             cmd.Parameters.AddWithValue("@phone_number", voucher.PhoneNumber == null ? (object)DBNull.Value : voucher.PhoneNumber).DbType = DbType.String;
             cmd.Parameters.AddWithValue("@email", voucher.Email == null ? (object)DBNull.Value : voucher.Email).DbType = DbType.String;
             var rowsAffected = cmd.ExecuteNonQuery();
             if (rowsAffected == 0)
                 throw new DataNotFoundException("Voucher");
         }
     }
     return voucher;
 }
        private VoucherDto FetchVoucher(SafeDataReader dr)
        {
            var voucher = new VoucherDto();
            // Value properties
            voucher.Id = dr.GetInt32("tran_id");
            voucher.Amount = (Decimal?)dr.GetValue("tran_amount");
            voucher.PersonId = !dr.IsDBNull("person_id") ? dr.GetString("person_id") : null;
            voucher.NamePrefix = !dr.IsDBNull("name_prefix") ? dr.GetString("name_prefix") : null;
            voucher.FirstName = !dr.IsDBNull("first_name") ? dr.GetString("first_name") : null;
            voucher.MiddleName = !dr.IsDBNull("middle_name") ? dr.GetString("middle_name") : null;
            voucher.LastName = !dr.IsDBNull("last_name") ? dr.GetString("last_name") : null;
            voucher.NameSuffix = !dr.IsDBNull("name_suffix") ? dr.GetString("name_suffix") : null;
            voucher.Title = !dr.IsDBNull("title") ? dr.GetString("title") : null;
            voucher.Company = !dr.IsDBNull("company") ? dr.GetString("company") : null;
            voucher.AddressLine1 = !dr.IsDBNull("address_1") ? dr.GetString("address_1") : null;
            voucher.AddressLine2 = !dr.IsDBNull("address_2") ? dr.GetString("address_2") : null;
            voucher.Municipality = !dr.IsDBNull("municipality") ? dr.GetString("municipality") : null;
            voucher.Region = !dr.IsDBNull("region") ? dr.GetString("region") : null;
            voucher.PostalCode = !dr.IsDBNull("postal_code") ? dr.GetString("postal_code") : null;
            voucher.Country = !dr.IsDBNull("country") ? dr.GetString("country") : null;
            voucher.PhoneNumber = !dr.IsDBNull("phone_number") ? dr.GetString("phone_number") : null;
            voucher.Email = !dr.IsDBNull("email") ? dr.GetString("email") : null;
            voucher.Updated = !dr.IsDBNull("updated") ? dr.GetSmartDate("updated", true) : null;

            return voucher;
        }