35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using Marco.Pms.Model.Mail;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using MongoDB.Driver;
|
|
|
|
namespace Marco.Pms.Helpers.Utility
|
|
{
|
|
public class MailLogHelper
|
|
{
|
|
private readonly IMongoCollection<MailLog> _collection;
|
|
private readonly ILogger<MailLogHelper> _logger;
|
|
public MailLogHelper(IConfiguration configuration, ILogger<MailLogHelper> logger)
|
|
{
|
|
_logger = logger;
|
|
var connectionString = configuration["MongoDB:MailConnectionString"];
|
|
var mongoUrl = new MongoUrl(connectionString);
|
|
var client = new MongoClient(mongoUrl); // Your MongoDB connection string
|
|
var mongoDB = client.GetDatabase(mongoUrl.DatabaseName); // Your MongoDB Database name
|
|
_collection = mongoDB.GetCollection<MailLog>("MailLogs");
|
|
}
|
|
|
|
public async Task AddWebMenuItemAsync(List<MailLog> mailLogs)
|
|
{
|
|
try
|
|
{
|
|
await _collection.InsertManyAsync(mailLogs);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error occurred while adding Mail Logs.");
|
|
}
|
|
}
|
|
}
|
|
}
|