示例#1
0
        /// <summary>
        /// Adds a new log entry to the database.
        /// </summary>
        /// <param name="log">The LogData object with the logging information</param>
        /// <returns>true if the add was successful, false otherwise</returns>
        public bool Add(LogData log)
        {
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                SqlCommand cmd = conn.CreateCommand();

                cmd.CommandText = "Insert into dbo.[Log] (UserId, Message) values (@userId, @message);";

                //User
                cmd.Parameters.AddWithValue("@userId", log.User.Id);

                //Message
                cmd.Parameters.AddWithValue("@message", log.Message);

                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return false;
                }
            }
            return true;
        }
示例#2
0
 public static LogData createFromReader(SqlDataReader reader)
 {
     LogData log = new LogData();
     log.DateTime = (DateTime)reader["DateTime"];
     log.User = new UserData((int)reader["UserId"]);
     log.Message = reader["Message"] as string;
     return log;
 }
示例#3
0
 /// <summary>
 /// Adds a new log entry to the database.
 /// </summary>
 /// <param name="log">The LogData object with the logging information</param>
 /// <returns>true if the add was successful, false otherwise</returns>
 public bool Add(LogData log)
 {
     return loggingDao.Add(log);
 }