public void AddLogEntry(ClientEntry entry, UserLogEntryType entryType) { //preconditions if (!this.Connected) throw new InvalidOperationException("Cannot add the log entry because the database is not connected."); if (!this.Authenticated) throw new InvalidOperationException("Cannot add the log entry because the current user is not authenticated with the Database."); if (entry == null) throw new ArgumentNullException("entry"); if (entryType != UserLogEntryType.Delete && !_entries.ContainsItem(entry)) throw new ArgumentException("The entry specified is not in this database."); if (entryType == UserLogEntryType.Delete && _entries.ContainsItem(entry)) throw new ArgumentException("A delete log entry cannot be written because the ClientEntry specified is in this database."); //prepare the description string description = String.Format("{0}: {1}", entry.Client.Name, entry.Name); var client = entry.Client; AddLogEntryInternal(entryType, client, description); }
private void AddLogEntryInternal(UserLogEntryType entryType, ClientRecord client, string description) { //send the command var addLogEntryCommand = new SqlCommand("sp_AddLogEntry", _connection) { CommandType = System.Data.CommandType.StoredProcedure }; addLogEntryCommand.Parameters.Add(new SqlParameter("username", this.CurrentUser.Name)); addLogEntryCommand.Parameters.Add(new SqlParameter("actiontype", (int)entryType)); addLogEntryCommand.Parameters.Add(new SqlParameter("clientid", client == null ? -1 : _clients[client])); addLogEntryCommand.Parameters.Add(new SqlParameter("description", description)); addLogEntryCommand.ExecuteNonQuery(); }