public async Task InsertAsync(Message message, Stream stream) { var messageFullPath = Path.Combine(_dataDirectory, Path.ChangeExtension(Guid.NewGuid().ToString(), ".eml")); message.Filename = Path.GetFileName(messageFullPath); using (var fileStream = File.Open(messageFullPath, FileMode.CreateNew)) { stream.CopyTo(fileStream); } using (var sqlConnection = new MySqlConnection(_connectionString)) { sqlConnection.Open(); var messageId = await sqlConnection.InsertAsync<long>(message); message.Id = messageId; } foreach (var recipient in message.Recipients) { recipient.MessageId = message.Id; await InsertAsync(recipient); } }
public async Task InsertAsync(Message message) { using (var sqlConnection = new MySqlConnection(_connectionString)) { sqlConnection.Open(); var messageId = await sqlConnection.InsertAsync<long>(message); message.Id = messageId; } foreach (var recipient in message.Recipients) { recipient.MessageId = message.Id; await InsertAsync(recipient); } }
public async Task InsertAsync(Recipient messageRecipient) { using (var sqlConnection = new MySqlConnection(_connectionString)) { sqlConnection.Open(); var messageRecipientId = await sqlConnection.InsertAsync<long>(messageRecipient); messageRecipient.Id = messageRecipientId; } }