コード例 #1
0
 /// <summary>
 /// Insert a new record.
 /// </summary>
 /// <param name="oLog">Log class</param>
 /// <returns>True if it is successful, false if it is failure</returns>
 public bool Insert(LogEntity oLog)
 {
     try
     {
         using (SqlConnection oConnection = new SqlConnection(ConnectionString))
         {
             oConnection.Open();
             using (SqlCommand oCommand = new SqlCommand("upsInsertLog", oConnection))
             {
                 oCommand.CommandType = System.Data.CommandType.StoredProcedure;
                 oCommand.Parameters.Clear();
                 oCommand.Parameters.Add("@LogMessage", SqlDbType.VarChar, 500).Value = oLog.LogMessage;
                 oCommand.Parameters.Add("@LogType", SqlDbType.Char, 1).Value = oLog.LogType;
                 oCommand.ExecuteNonQuery();
             }
         }
         // Here we use "using" to make Dispose to the clases such as "SqlConnection" and "SqlCommand",
         // Also we use store procedure to avoid sql injection.
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
コード例 #2
0
 private static void LogToDatabase(string message, Enums.MessageType messageType)
 {
     try
     {
         LogEntity oLog = new LogEntity() { LogMessage = message, LogType = ((int)messageType).ToString() };
         var result = LogDomain.Instance.Insert(oLog);
     }
     catch (Exception ex)
     {
         throw new Exception(Constants.ErrorDB, ex);
     }
 }
コード例 #3
0
 public bool Insert(LogEntity oLog)
 {
     return repository.Insert(oLog);
 }