private SystemEvent GetSystemEventFromRecord(NpgsqlDataReader reader)
 {
     var systemEvent = new SystemEvent
     {
         Command = (CommandType)reader.GetValue(8),
         StockSymbol = (reader.IsDBNull(9)) ? null : reader.GetString(9),
         Funds = (reader.IsDBNull(10)) ? null : (decimal?) reader.GetDecimal(10),
         FileName = (reader.IsDBNull(11)) ? null : reader.GetString(11)
     };
     FillBaseEventPropertiesFromRecord(systemEvent, reader);
     return systemEvent;
 }
        public void LogSystemEvent(SystemEvent systemEvent)
        {
            using (var command = new NpgsqlCommand("log_system_event"))
            {
                Log.DebugFormat("Inserting system event {0} into databse...", systemEvent.Id);

                command.CommandType = System.Data.CommandType.StoredProcedure;

                AddCommonEventPropertyParametersToCommand(command, systemEvent);

                command.Parameters.Add(new NpgsqlParameter
                {
                    NpgsqlDbType = NpgsqlDbType.Enum,
                    Value = systemEvent.Command
                });

                command.Parameters.Add(new NpgsqlParameter
                {
                    NpgsqlDbType = NpgsqlDbType.Char,
                    Value = ((object) systemEvent.StockSymbol) ?? DBNull.Value
                });

                command.Parameters.Add(new NpgsqlParameter
                {
                    NpgsqlDbType = NpgsqlDbType.Money,
                    Value = ((object) systemEvent.Funds) ?? DBNull.Value
                });

                command.Parameters.Add(new NpgsqlParameter
                {
                    NpgsqlDbType = NpgsqlDbType.Varchar,
                    Value = ((object) systemEvent.FileName) ?? DBNull.Value
                });

                int id = ExecuteInsertCommand(command);

                Log.DebugFormat(CultureInfo.InvariantCulture,
                    "Successfully inserted system event {0} (database id = {1}).", systemEvent.Id, id);
            }
        }