Compare commits
No commits in common. "d84b01473ac79c3c93268564b2bea79933808e57" and "3a45bded0807fc7dba9e5737bd04f29f2031865d" have entirely different histories.
d84b01473a
...
3a45bded08
@ -1,91 +0,0 @@
|
||||
using Marco.Pms.Model.MongoDBModels;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using System.Collections;
|
||||
|
||||
namespace Marco.Pms.CacheHelper
|
||||
{
|
||||
public class UpdateLogHelper
|
||||
{
|
||||
private readonly IMongoDatabase _mongoDatabase;
|
||||
public UpdateLogHelper(IConfiguration configuration)
|
||||
{
|
||||
var connectionString = configuration["MongoDB:ConnectionString"];
|
||||
var mongoUrl = new MongoUrl(connectionString);
|
||||
var client = new MongoClient(mongoUrl); // Your MongoDB connection string
|
||||
_mongoDatabase = client.GetDatabase(mongoUrl.DatabaseName); // Your MongoDB Database name
|
||||
}
|
||||
public async Task PushToUpdateLogs(UpdateLogsObject oldObject, string collectionName)
|
||||
{
|
||||
var collection = _mongoDatabase.GetCollection<UpdateLogsObject>(collectionName);
|
||||
await collection.InsertOneAsync(oldObject);
|
||||
}
|
||||
|
||||
public async Task<List<UpdateLogsObject>> GetFromUpdateLogsByEntityId(Guid entityId, string collectionName)
|
||||
{
|
||||
var collection = _mongoDatabase.GetCollection<UpdateLogsObject>(collectionName);
|
||||
var filter = Builders<UpdateLogsObject>.Filter.Eq(p => p.EntityId, entityId.ToString());
|
||||
|
||||
List<UpdateLogsObject> result = await collection
|
||||
.Find(filter)
|
||||
.ToListAsync();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<UpdateLogsObject>> GetFromUpdateLogsByUpdetedById(Guid updatedById, string collectionName)
|
||||
{
|
||||
var collection = _mongoDatabase.GetCollection<UpdateLogsObject>(collectionName);
|
||||
var filter = Builders<UpdateLogsObject>.Filter.Eq(p => p.UpdatedById, updatedById.ToString());
|
||||
|
||||
List<UpdateLogsObject> result = await collection
|
||||
.Find(filter)
|
||||
.ToListAsync();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public BsonDocument NormalizeGuidsToStrings(object entity)
|
||||
{
|
||||
var bson = new BsonDocument();
|
||||
|
||||
var props = entity.GetType().GetProperties();
|
||||
foreach (var prop in props)
|
||||
{
|
||||
var value = prop.GetValue(entity);
|
||||
if (value == null)
|
||||
{
|
||||
bson[prop.Name] = BsonNull.Value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value is Guid guidValue)
|
||||
{
|
||||
bson[prop.Name] = guidValue.ToString(); // store Guid as string
|
||||
}
|
||||
else if (value is string || value.GetType().IsPrimitive || value is DateTime)
|
||||
{
|
||||
bson[prop.Name] = BsonValue.Create(value); // simple types
|
||||
}
|
||||
else if (value is IEnumerable list && !(value is string))
|
||||
{
|
||||
var array = new BsonArray();
|
||||
foreach (var item in list)
|
||||
{
|
||||
array.Add(NormalizeGuidsToStrings(item)); // recursive
|
||||
}
|
||||
bson[prop.Name] = array;
|
||||
}
|
||||
else
|
||||
{
|
||||
// nested object
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return bson;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
{
|
||||
public class UpdateLogsObject
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.String)]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public string EntityId { get; set; } = string.Empty;
|
||||
public BsonDocument? OldObject { get; set; }
|
||||
public string UpdatedById { get; set; } = string.Empty;
|
||||
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
using System.Text;
|
||||
using Marco.Pms.CacheHelper;
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.Authentication;
|
||||
@ -15,7 +16,6 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Serilog;
|
||||
using System.Text;
|
||||
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@ -139,7 +139,6 @@ builder.Services.AddScoped<DirectoryHelper>();
|
||||
builder.Services.AddScoped<MasterHelper>();
|
||||
builder.Services.AddScoped<ReportHelper>();
|
||||
builder.Services.AddScoped<CacheUpdateHelper>();
|
||||
builder.Services.AddScoped<UpdateLogHelper>();
|
||||
builder.Services.AddScoped<ProjectCache>();
|
||||
builder.Services.AddScoped<EmployeeCache>();
|
||||
builder.Services.AddSingleton<ILoggingService, LoggingService>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user