/// <summary> /// Gets the sendID's internal ID from the database. If the record doesn't exist /// then it will be created. /// </summary> /// <param name="sendID">The SendID to get the internal ID for.</param> /// <returns></returns> public static async Task <Send> CreateAndGetInternalSendIDAsync(string sendID) { using (SqlConnection conn = MantaDB.GetSqlConnection()) { SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = @" BEGIN TRANSACTION MERGE man_mta_send WITH (HOLDLOCK) AS target USING (SELECT @sndID) AS source(mta_send_id) ON (target.mta_send_id = source.mta_send_id) WHEN NOT MATCHED THEN INSERT (mta_send_id, mta_sendStatus_id, mta_send_internalId, mta_send_createdTimestamp) VALUES (@sndID, @activeStatusID, ISNULL((SELECT MAX(mta_send_internalID) + 1 FROM man_mta_send), 1), GETUTCDATE()); COMMIT TRANSACTION SELECT * FROM man_mta_send WITH(nolock) WHERE mta_send_id = @sndID"; cmd.Parameters.AddWithValue("@sndID", sendID); cmd.Parameters.AddWithValue("@activeStatusID", (int)SendStatus.Active); return(await DataRetrieval.GetSingleObjectFromDatabaseAsync <Send>(cmd, CreateAndFillSendFromRecord).ConfigureAwait(false)); } }
/// <summary> /// Gets the specified send. /// </summary> /// <param name="internalSendID">Internal ID of the Send to get.</param> /// <returns>The specified Send or NULL if none with the ID exist.</returns> public static async Task <Send> GetSendAsync(int internalSendID) { using (SqlConnection conn = MantaDB.GetSqlConnection()) { SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = @" SELECT * FROM man_mta_send WITH(NOLOCK) WHERE mta_send_internalId = @internalSndID"; cmd.Parameters.AddWithValue("@internalSndID", internalSendID); return(await DataRetrieval.GetSingleObjectFromDatabaseAsync <Send>(cmd, CreateAndFillSendFromRecord)); } }