using Marco.Pms.DataAccess.Data; using Marco.Pms.Model.MongoDBModels; using Microsoft.Extensions.Configuration; using MongoDB.Driver; namespace Marco.Pms.CacheHelper { public class ReportCache { private readonly ApplicationDbContext _context; private readonly IMongoCollection _projectReportCollection; public ReportCache(ApplicationDbContext context, IConfiguration configuration) { var connectionString = configuration["MongoDB:ConnectionString"]; _context = context; var mongoUrl = new MongoUrl(connectionString); var client = new MongoClient(mongoUrl); // Your MongoDB connection string var mongoDB = client.GetDatabase(mongoUrl.DatabaseName); // Your MongoDB Database name _projectReportCollection = mongoDB.GetCollection("ProjectReportMail"); } /// /// Retrieves project report emails from the cache based on their sent status. /// /// True to get sent reports, false to get unsent reports. /// A list of ProjectReportEmailMongoDB objects. public async Task> GetProjectReportMailFromCache(bool isSent) { var filter = Builders.Filter.Eq(p => p.IsSent, isSent); var reports = await _projectReportCollection.Find(filter).ToListAsync(); return reports; } /// /// Adds a project report email to the cache. /// /// The ProjectReportEmailMongoDB object to add. /// A Task representing the asynchronous operation. public async Task AddProjectReportMailToCache(ProjectReportEmailMongoDB report) { // Consider adding validation or logging here. await _projectReportCollection.InsertOneAsync(report); } } }