37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using adas_core.Domain.Models.MongoModels;
|
|
using adas_core.Infrastructure.Utils.MongoMaps.Interfaz;
|
|
using MongoDB.Bson.Serialization;
|
|
|
|
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
|
|
|
public class AuthMapContributor : IEntityMapContributor
|
|
{
|
|
public void RegisterMaps()
|
|
{
|
|
if (!BsonClassMap.IsClassMapRegistered(typeof(User)))
|
|
BsonClassMap.RegisterClassMap<User>(cm =>
|
|
{
|
|
cm.AutoMap();
|
|
cm.MapMember(c => c.Password)
|
|
.SetIgnoreIfNull(true)
|
|
.SetShouldSerializeMethod(obj => !string.IsNullOrEmpty(((User)obj).Password));
|
|
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
|
cm.MapMember(c => c.LockExpirationDate)
|
|
.SetIgnoreIfNull(true);
|
|
cm.MapMember(c => c.Authorization).SetElementName("Authorization")
|
|
.SetShouldSerializeMethod(_ => false);
|
|
});
|
|
|
|
if (!BsonClassMap.IsClassMapRegistered(typeof(Authorization)))
|
|
BsonClassMap.RegisterClassMap<Authorization>(cm =>
|
|
{
|
|
cm.AutoMap();
|
|
|
|
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
|
cm.MapMember(c => c.UnitId).SetIgnoreIfNull(true);
|
|
cm.UnmapProperty(c => c.User);
|
|
cm.UnmapProperty(c => c.Display);
|
|
cm.UnmapProperty(c => c.Unit);
|
|
});
|
|
}
|
|
} |