Infrastructure repositories now inherit AbstractRepository and implement concrete mapping logic

This commit is contained in:
Veljko Tosic
2026-02-11 02:25:14 +01:00
parent c23e489db2
commit e7abe1eaed
8 changed files with 208 additions and 200 deletions

View File

@@ -0,0 +1,55 @@
using AipsCore.Domain.Abstract;
using AipsCore.Domain.Common.ValueObjects;
using AipsCore.Infrastructure.Persistence.Db;
using Microsoft.EntityFrameworkCore;
namespace AipsCore.Infrastructure.Persistence.Abstract;
public abstract class AbstractRepository<TEntity, TId, TPersistenceEntity> : IAbstractRepository<TEntity, TId>
where TEntity : DomainEntity<TId>
where TId : DomainId
where TPersistenceEntity : class
{
protected readonly AipsDbContext Context;
protected readonly DbSet<TPersistenceEntity> DbSet;
protected AbstractRepository(AipsDbContext context)
{
Context = context;
DbSet = Context.Set<TPersistenceEntity>();
}
public async Task<TEntity?> GetByIdAsync(TId id, CancellationToken cancellationToken = default)
{
var persistenceEntity = await DbSet.FindAsync([new Guid(id.IdValue)], cancellationToken);
return persistenceEntity != null ? MapToDomainEntity(persistenceEntity) : null;
}
public async Task SaveAsync(TEntity entity, CancellationToken cancellationToken = default)
{
var persistenceEntity = await DbSet.FindAsync([new Guid(entity.Id.IdValue)], cancellationToken);
if (persistenceEntity == null)
{
persistenceEntity = MapToPersistenceEntity(entity);
await DbSet.AddAsync(persistenceEntity, cancellationToken);
}
else
{
UpdatePersistenceEntity(persistenceEntity, entity);
DbSet.Update(persistenceEntity);
}
}
public async Task AddAsync(TEntity entity, CancellationToken cancellationToken = default)
{
var persistenceEntity = MapToPersistenceEntity(entity);
await DbSet.AddAsync(persistenceEntity, cancellationToken);
}
protected abstract TEntity MapToDomainEntity(TPersistenceEntity persistenceEntity);
protected abstract TPersistenceEntity MapToPersistenceEntity(TEntity domainEntity);
protected abstract void UpdatePersistenceEntity(TPersistenceEntity persistenceEntity, TEntity domainEntity);
}

View File

@@ -8,19 +8,19 @@ namespace AipsCore.Infrastructure.Persistence.Shape.Mappers;
public static partial class ShapeMappers public static partial class ShapeMappers
{ {
public static Domain.Models.Shape.Shape EntityToModel(Shape shape) public static Domain.Models.Shape.Shape MapToDomainEntity(Shape shape)
{ {
return shape.Type switch return shape.Type switch
{ {
ShapeType.Rectangle => EntityToRectangle(shape), ShapeType.Rectangle => PersistenceEntityToRectangle(shape),
ShapeType.Line => EntityToLine(shape), ShapeType.Line => PersistenceEntityToLine(shape),
ShapeType.Arrow => EntityToArrow(shape), ShapeType.Arrow => PersistenceEntityToArrow(shape),
ShapeType.Text => EntityToTextShape(shape), ShapeType.Text => PersistenceEntityToTextShape(shape),
_ => throw new ArgumentOutOfRangeException() _ => throw new ArgumentOutOfRangeException()
}; };
} }
public static Rectangle EntityToRectangle(Shape shape) private static Rectangle PersistenceEntityToRectangle(Shape shape)
{ {
return Rectangle.Create( return Rectangle.Create(
shape.Id.ToString(), shape.Id.ToString(),
@@ -31,7 +31,7 @@ public static partial class ShapeMappers
shape.Thickness!.Value); shape.Thickness!.Value);
} }
public static Line EntityToLine(Shape shape) private static Line PersistenceEntityToLine(Shape shape)
{ {
return Line.Create( return Line.Create(
shape.Id.ToString(), shape.Id.ToString(),
@@ -43,7 +43,7 @@ public static partial class ShapeMappers
shape.Thickness!.Value); shape.Thickness!.Value);
} }
public static Arrow EntityToArrow(Shape shape) private static Arrow PersistenceEntityToArrow(Shape shape)
{ {
return Arrow.Create( return Arrow.Create(
shape.Id.ToString(), shape.Id.ToString(),
@@ -55,7 +55,7 @@ public static partial class ShapeMappers
shape.Thickness!.Value); shape.Thickness!.Value);
} }
public static TextShape EntityToTextShape(Shape shape) private static TextShape PersistenceEntityToTextShape(Shape shape)
{ {
return TextShape.Create( return TextShape.Create(
shape.Id.ToString(), shape.Id.ToString(),

View File

@@ -9,21 +9,21 @@ namespace AipsCore.Infrastructure.Persistence.Shape.Mappers;
public static partial class ShapeMappers public static partial class ShapeMappers
{ {
public static Shape ModelToEntity(Domain.Models.Shape.Shape model) public static Shape MapToPersistenceEntity(Domain.Models.Shape.Shape model)
{ {
return model.ShapeType switch return model.ShapeType switch
{ {
ShapeType.Rectangle => RectangleToEntity((Rectangle)model), ShapeType.Rectangle => RectangleToPersistenceEntity((Rectangle)model),
ShapeType.Line => LineToEntity((Line)model), ShapeType.Line => LineToPersistenceEntity((Line)model),
ShapeType.Arrow => ArrowToEntity((Arrow)model), ShapeType.Arrow => ArrowToPersistenceEntity((Arrow)model),
ShapeType.Text => TextShapeToEntity((TextShape)model), ShapeType.Text => TextShapeToPersistenceEntity((TextShape)model),
_ => throw new ArgumentOutOfRangeException() _ => throw new ArgumentOutOfRangeException()
}; };
} }
public static Shape RectangleToEntity(Rectangle rectangle) private static Shape RectangleToPersistenceEntity(Rectangle rectangle)
{ {
return new Shape() return new Shape
{ {
Id = new Guid(rectangle.Id.Value), Id = new Guid(rectangle.Id.Value),
Type = rectangle.ShapeType, Type = rectangle.ShapeType,
@@ -38,9 +38,9 @@ public static partial class ShapeMappers
}; };
} }
public static Shape LineToEntity(Line line) private static Shape LineToPersistenceEntity(Line line)
{ {
return new Shape() return new Shape
{ {
Id = new Guid(line.Id.Value), Id = new Guid(line.Id.Value),
Type = line.ShapeType, Type = line.ShapeType,
@@ -55,9 +55,9 @@ public static partial class ShapeMappers
}; };
} }
public static Shape ArrowToEntity(Arrow arrow) private static Shape ArrowToPersistenceEntity(Arrow arrow)
{ {
return new Shape() return new Shape
{ {
Id = new Guid(arrow.Id.Value), Id = new Guid(arrow.Id.Value),
Type = arrow.ShapeType, Type = arrow.ShapeType,
@@ -72,9 +72,9 @@ public static partial class ShapeMappers
}; };
} }
public static Shape TextShapeToEntity(TextShape textShape) private static Shape TextShapeToPersistenceEntity(TextShape textShape)
{ {
return new Shape() return new Shape
{ {
Id = new Guid(textShape.Id.Value), Id = new Guid(textShape.Id.Value),
Type = textShape.ShapeType, Type = textShape.ShapeType,

View File

@@ -8,7 +8,7 @@ namespace AipsCore.Infrastructure.Persistence.Shape.Mappers;
public static partial class ShapeMappers public static partial class ShapeMappers
{ {
public static void UpdateEntity(Shape entity, Domain.Models.Shape.Shape model) public static void UpdatePersistenceEntity(Shape entity, Domain.Models.Shape.Shape model)
{ {
entity.WhiteboardId = new Guid(model.WhiteboardId.IdValue); entity.WhiteboardId = new Guid(model.WhiteboardId.IdValue);
entity.PositionX = model.Position.X; entity.PositionX = model.Position.X;
@@ -32,28 +32,28 @@ public static partial class ShapeMappers
}; };
} }
public static void UpdateEntityFromRectangle(Shape entity, Rectangle rectangle) private static void UpdateEntityFromRectangle(Shape entity, Rectangle rectangle)
{ {
entity.EndPositionX = rectangle.EndPosition.X; entity.EndPositionX = rectangle.EndPosition.X;
entity.EndPositionY = rectangle.EndPosition.Y; entity.EndPositionY = rectangle.EndPosition.Y;
entity.Thickness = rectangle.BorderThickness.Value; entity.Thickness = rectangle.BorderThickness.Value;
} }
public static void UpdateEntityFromLine(Shape entity, Line line) private static void UpdateEntityFromLine(Shape entity, Line line)
{ {
entity.EndPositionX = line.EndPosition.X; entity.EndPositionX = line.EndPosition.X;
entity.EndPositionY = line.EndPosition.Y; entity.EndPositionY = line.EndPosition.Y;
entity.Thickness = line.Thickness.Value; entity.Thickness = line.Thickness.Value;
} }
public static void UpdateEntityFromArrow(Shape entity, Arrow arrow) private static void UpdateEntityFromArrow(Shape entity, Arrow arrow)
{ {
entity.EndPositionX = arrow.EndPosition.X; entity.EndPositionX = arrow.EndPosition.X;
entity.EndPositionY = arrow.EndPosition.Y; entity.EndPositionY = arrow.EndPosition.Y;
entity.Thickness = arrow.Thickness.Value; entity.Thickness = arrow.Thickness.Value;
} }
public static void UpdateEntityFromTextShape(Shape entity, TextShape textShape) private static void UpdateEntityFromTextShape(Shape entity, TextShape textShape)
{ {
entity.TextValue = textShape.TextShapeValue.Text; entity.TextValue = textShape.TextShapeValue.Text;
entity.TextSize = textShape.TextShapeSize.Size; entity.TextSize = textShape.TextShapeSize.Size;

View File

@@ -1,42 +1,31 @@
using AipsCore.Domain.Models.Shape.External; using AipsCore.Domain.Models.Shape.External;
using AipsCore.Domain.Models.Shape.ValueObjects; using AipsCore.Domain.Models.Shape.ValueObjects;
using AipsCore.Infrastructure.Persistence.Abstract;
using AipsCore.Infrastructure.Persistence.Db; using AipsCore.Infrastructure.Persistence.Db;
using AipsCore.Infrastructure.Persistence.Shape.Mappers; using AipsCore.Infrastructure.Persistence.Shape.Mappers;
namespace AipsCore.Infrastructure.Persistence.Shape; namespace AipsCore.Infrastructure.Persistence.Shape;
public class ShapeRepository : IShapeRepository public class ShapeRepository : AbstractRepository<Domain.Models.Shape.Shape, ShapeId, Shape>, IShapeRepository
{ {
private readonly AipsDbContext _context;
public ShapeRepository(AipsDbContext context) public ShapeRepository(AipsDbContext context)
: base(context)
{ {
_context = context;
} }
public async Task<Domain.Models.Shape.Shape?> Get(ShapeId id, CancellationToken cancellationToken = default) protected override Domain.Models.Shape.Shape MapToDomainEntity(Shape persistenceEntity)
{ {
var entity = await _context.Shapes.FindAsync([new Guid(id.Value)], cancellationToken); return ShapeMappers.MapToDomainEntity(persistenceEntity);
if (entity is null) return null;
return ShapeMappers.EntityToModel(entity);
} }
public async Task Add(Domain.Models.Shape.Shape shape, CancellationToken cancellationToken = default) protected override Shape MapToPersistenceEntity(Domain.Models.Shape.Shape domainEntity)
{ {
var entity = await _context.Shapes.FindAsync([new Guid(shape.Id.Value)], cancellationToken); return ShapeMappers.MapToPersistenceEntity(domainEntity);
if (entity is not null)
{
ShapeMappers.UpdateEntity(entity, shape);
}
else
{
var newEntity = ShapeMappers.ModelToEntity(shape);
await _context.Shapes.AddAsync(newEntity, cancellationToken);
} }
protected override void UpdatePersistenceEntity(Shape persistenceEntity, Domain.Models.Shape.Shape domainEntity)
{
ShapeMappers.UpdatePersistenceEntity(persistenceEntity, domainEntity);
} }
} }

View File

@@ -1,58 +1,45 @@
using AipsCore.Domain.Models.User.External; using AipsCore.Domain.Models.User.External;
using AipsCore.Domain.Models.User.ValueObjects; using AipsCore.Domain.Models.User.ValueObjects;
using AipsCore.Infrastructure.Persistence.Abstract;
using AipsCore.Infrastructure.Persistence.Db; using AipsCore.Infrastructure.Persistence.Db;
namespace AipsCore.Infrastructure.Persistence.User; namespace AipsCore.Infrastructure.Persistence.User;
public class UserRepository : IUserRepository public class UserRepository : AbstractRepository<Domain.Models.User.User, UserId, User>, IUserRepository
{ {
private readonly AipsDbContext _context;
public UserRepository(AipsDbContext context) public UserRepository(AipsDbContext context)
: base(context)
{ {
_context = context;
} }
public async Task<Domain.Models.User.User?> Get(UserId userId, CancellationToken cancellationToken = default) protected override Domain.Models.User.User MapToDomainEntity(User persistenceEntity)
{ {
var userEntity = await _context.Users.FindAsync([new Guid(userId.IdValue), cancellationToken], cancellationToken: cancellationToken);
if (userEntity is null) return null;
return Domain.Models.User.User.Create( return Domain.Models.User.User.Create(
userEntity.Id.ToString(), persistenceEntity.Id.ToString(),
userEntity.Email, persistenceEntity.Email,
userEntity.Username, persistenceEntity.Username,
userEntity.CreatedAt, persistenceEntity.CreatedAt,
userEntity.DeletedAt); persistenceEntity.DeletedAt
);
} }
public async Task Save(Domain.Models.User.User user, CancellationToken cancellationToken = default) protected override User MapToPersistenceEntity(Domain.Models.User.User domainEntity)
{ {
// ReSharper disable once MethodSupportsCancellation return new User
var userEntity = await _context.Users.FindAsync(new Guid(user.Id.IdValue));
if (userEntity is not null)
{ {
userEntity.Email = user.Email.EmailValue; Id = new Guid(domainEntity.Id.IdValue),
userEntity.Username = user.Username.UsernameValue; Email = domainEntity.Email.EmailValue,
userEntity.CreatedAt = user.CreatedAt.CreatedAtValue; Username = domainEntity.Username.UsernameValue,
userEntity.DeletedAt = user.DeletedAt.DeletedAtValue; CreatedAt = domainEntity.CreatedAt.CreatedAtValue,
DeletedAt = domainEntity.DeletedAt.DeletedAtValue
_context.Users.Update(userEntity);
}
else
{
userEntity = new User()
{
Id = new Guid(user.Id.IdValue),
Email = user.Email.EmailValue,
Username = user.Username.UsernameValue,
CreatedAt = user.CreatedAt.CreatedAtValue,
DeletedAt = user.DeletedAt.DeletedAtValue
}; };
_context.Users.Add(userEntity);
} }
protected override void UpdatePersistenceEntity(User persistenceEntity, Domain.Models.User.User domainEntity)
{
persistenceEntity.Email = domainEntity.Email.EmailValue;
persistenceEntity.Username = domainEntity.Username.UsernameValue;
persistenceEntity.CreatedAt = domainEntity.CreatedAt.CreatedAtValue;
persistenceEntity.DeletedAt = domainEntity.DeletedAt.DeletedAtValue;
} }
} }

View File

@@ -1,76 +1,64 @@
using AipsCore.Domain.Models.Whiteboard.External; using AipsCore.Domain.Models.Whiteboard.External;
using AipsCore.Domain.Models.Whiteboard.ValueObjects; using AipsCore.Domain.Models.Whiteboard.ValueObjects;
using AipsCore.Infrastructure.Persistence.Abstract;
using AipsCore.Infrastructure.Persistence.Db; using AipsCore.Infrastructure.Persistence.Db;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace AipsCore.Infrastructure.Persistence.Whiteboard; namespace AipsCore.Infrastructure.Persistence.Whiteboard;
public class WhiteboardRepository : IWhiteboardRepository public class WhiteboardRepository
: AbstractRepository<Domain.Models.Whiteboard.Whiteboard, WhiteboardId, Whiteboard>, IWhiteboardRepository
{ {
private readonly AipsDbContext _context;
public WhiteboardRepository(AipsDbContext context) public WhiteboardRepository(AipsDbContext context)
: base(context)
{ {
_context = context;
} }
public async Task<Domain.Models.Whiteboard.Whiteboard?> Get(WhiteboardId whiteboardId, CancellationToken cancellationToken = default) protected override Domain.Models.Whiteboard.Whiteboard MapToDomainEntity(Whiteboard persistenceEntity)
{ {
var whiteboardEntity = await _context.Whiteboards.FindAsync([new Guid(whiteboardId.IdValue), cancellationToken], cancellationToken: cancellationToken);
if (whiteboardEntity is null) return null;
return Domain.Models.Whiteboard.Whiteboard.Create( return Domain.Models.Whiteboard.Whiteboard.Create(
whiteboardEntity.Id.ToString(), persistenceEntity.Id.ToString(),
whiteboardEntity.OwnerId.ToString(), persistenceEntity.OwnerId.ToString(),
whiteboardEntity.Code, persistenceEntity.Code,
whiteboardEntity.Title, persistenceEntity.Title,
whiteboardEntity.CreatedAt, persistenceEntity.CreatedAt,
whiteboardEntity.DeletedAt, persistenceEntity.DeletedAt,
whiteboardEntity.MaxParticipants, persistenceEntity.MaxParticipants,
whiteboardEntity.JoinPolicy, persistenceEntity.JoinPolicy,
whiteboardEntity.State); persistenceEntity.State
);
} }
public async Task Save(Domain.Models.Whiteboard.Whiteboard whiteboard, CancellationToken cancellationToken = default) protected override Whiteboard MapToPersistenceEntity(Domain.Models.Whiteboard.Whiteboard domainEntity)
{ {
var whiteboardEntity = await _context.Whiteboards.FindAsync(new Guid(whiteboard.Id.IdValue)); return new Whiteboard
if (whiteboardEntity is not null)
{ {
whiteboardEntity.OwnerId = new Guid(whiteboard.WhiteboardOwnerId.IdValue); Id = new Guid(domainEntity.Id.IdValue),
whiteboardEntity.Code = whiteboard.Code.CodeValue; OwnerId = new Guid(domainEntity.WhiteboardOwnerId.IdValue),
whiteboardEntity.Title = whiteboard.Title.TitleValue; Code = domainEntity.Code.CodeValue,
whiteboardEntity.CreatedAt = whiteboard.CreatedAt.CreatedAtValue; Title = domainEntity.Title.TitleValue,
whiteboardEntity.DeletedAt = whiteboard.DeletedAt.DeletedAtValue; CreatedAt = domainEntity.CreatedAt.CreatedAtValue,
whiteboardEntity.MaxParticipants = whiteboard.MaxParticipants.MaxParticipantsValue; DeletedAt = domainEntity.DeletedAt.DeletedAtValue,
whiteboardEntity.JoinPolicy = whiteboard.JoinPolicy; MaxParticipants = domainEntity.MaxParticipants.MaxParticipantsValue,
whiteboardEntity.State = whiteboard.State; JoinPolicy = domainEntity.JoinPolicy,
State = domainEntity.State
_context.Whiteboards.Update(whiteboardEntity);
}
else
{
whiteboardEntity = new Whiteboard()
{
Id = new Guid(whiteboard.Id.IdValue),
OwnerId = new Guid(whiteboard.WhiteboardOwnerId.IdValue),
Code = whiteboard.Code.CodeValue,
Title = whiteboard.Title.TitleValue,
CreatedAt = whiteboard.CreatedAt.CreatedAtValue,
DeletedAt = whiteboard.DeletedAt.DeletedAtValue,
MaxParticipants = whiteboard.MaxParticipants.MaxParticipantsValue,
JoinPolicy = whiteboard.JoinPolicy,
State = whiteboard.State
}; };
_context.Whiteboards.Add(whiteboardEntity);
} }
protected override void UpdatePersistenceEntity(Whiteboard persistenceEntity, Domain.Models.Whiteboard.Whiteboard domainEntity)
{
persistenceEntity.Code = domainEntity.Code.CodeValue;
persistenceEntity.Title = domainEntity.Title.TitleValue;
persistenceEntity.CreatedAt = domainEntity.CreatedAt.CreatedAtValue;
persistenceEntity.DeletedAt = domainEntity.DeletedAt.DeletedAtValue;
persistenceEntity.MaxParticipants = domainEntity.MaxParticipants.MaxParticipantsValue;
persistenceEntity.JoinPolicy = domainEntity.JoinPolicy;
persistenceEntity.State = domainEntity.State;
} }
public async Task<bool> WhiteboardCodeExists(WhiteboardCode whiteboardCode) public async Task<bool> WhiteboardCodeExists(WhiteboardCode whiteboardCode)
{ {
var codeExists = await _context.Whiteboards.AnyAsync(w => w.Code == whiteboardCode.CodeValue); return await Context.Whiteboards.AnyAsync(w => w.Code == whiteboardCode.CodeValue);
return codeExists;
} }
} }

View File

@@ -1,63 +1,52 @@
using AipsCore.Domain.Models.WhiteboardMembership.External; using AipsCore.Domain.Models.WhiteboardMembership.External;
using AipsCore.Domain.Models.WhiteboardMembership.ValueObjects; using AipsCore.Domain.Models.WhiteboardMembership.ValueObjects;
using AipsCore.Infrastructure.Persistence.Abstract;
using AipsCore.Infrastructure.Persistence.Db; using AipsCore.Infrastructure.Persistence.Db;
namespace AipsCore.Infrastructure.Persistence.WhiteboardMembership; namespace AipsCore.Infrastructure.Persistence.WhiteboardMembership;
public class WhiteboardMembershipRepository : IWhiteboardMembershipRepository public class WhiteboardMembershipRepository
: AbstractRepository<Domain.Models.WhiteboardMembership.WhiteboardMembership, WhiteboardMembershipId, WhiteboardMembership>,
IWhiteboardMembershipRepository
{ {
private readonly AipsDbContext _context;
public WhiteboardMembershipRepository(AipsDbContext context) public WhiteboardMembershipRepository(AipsDbContext context)
: base(context)
{ {
_context = context;
} }
public async Task<Domain.Models.WhiteboardMembership.WhiteboardMembership?> Get(WhiteboardMembershipId whiteboardMembershipId, CancellationToken cancellationToken = default) protected override Domain.Models.WhiteboardMembership.WhiteboardMembership MapToDomainEntity(WhiteboardMembership persistenceEntity)
{ {
var whiteboardMembershipEntity = await _context.WhiteboardMemberships.FindAsync(new Guid(whiteboardMembershipId.IdValue));
if (whiteboardMembershipEntity is null) return null;
return Domain.Models.WhiteboardMembership.WhiteboardMembership.Create( return Domain.Models.WhiteboardMembership.WhiteboardMembership.Create(
whiteboardMembershipEntity.Id.ToString(), persistenceEntity.Id.ToString(),
whiteboardMembershipEntity.WhiteboardId.ToString(), persistenceEntity.WhiteboardId.ToString(),
whiteboardMembershipEntity.UserId.ToString(), persistenceEntity.UserId.ToString(),
whiteboardMembershipEntity.IsBanned, persistenceEntity.IsBanned,
whiteboardMembershipEntity.EditingEnabled, persistenceEntity.EditingEnabled,
whiteboardMembershipEntity.CanJoin, persistenceEntity.CanJoin,
whiteboardMembershipEntity.LastInteractedAt); persistenceEntity.LastInteractedAt
);
} }
public async Task Save(Domain.Models.WhiteboardMembership.WhiteboardMembership whiteboardMembership, CancellationToken cancellationToken = default) protected override WhiteboardMembership MapToPersistenceEntity(Domain.Models.WhiteboardMembership.WhiteboardMembership domainEntity)
{ {
var whiteboardMembershipEntity = await _context.WhiteboardMemberships.FindAsync(new Guid(whiteboardMembership.Id.IdValue)); return new WhiteboardMembership
if (whiteboardMembershipEntity is not null)
{ {
whiteboardMembershipEntity.IsBanned = whiteboardMembership.IsBanned.IsBannedValue; Id = new Guid(domainEntity.Id.IdValue),
whiteboardMembershipEntity.EditingEnabled = whiteboardMembership.EditingEnabled.EditingEnabledValue; WhiteboardId = new Guid(domainEntity.WhiteboardId.IdValue),
whiteboardMembershipEntity.CanJoin = whiteboardMembership.CanJoin.CanJoinValue; UserId = new Guid(domainEntity.UserId.IdValue),
whiteboardMembershipEntity.LastInteractedAt = whiteboardMembership.LastInteractedAt.LastInteractedAtValue; IsBanned = domainEntity.IsBanned.IsBannedValue,
EditingEnabled = domainEntity.EditingEnabled.EditingEnabledValue,
_context.Update(whiteboardMembershipEntity); CanJoin = domainEntity.CanJoin.CanJoinValue,
} LastInteractedAt = domainEntity.LastInteractedAt.LastInteractedAtValue
else
{
whiteboardMembershipEntity = new WhiteboardMembership()
{
Id = new Guid(whiteboardMembership.Id.IdValue),
WhiteboardId = new Guid(whiteboardMembership.WhiteboardId.IdValue),
Whiteboard = null,
UserId = new Guid(whiteboardMembership.UserId.IdValue),
User = null,
IsBanned = whiteboardMembership.IsBanned.IsBannedValue,
EditingEnabled = whiteboardMembership.EditingEnabled.EditingEnabledValue,
CanJoin = whiteboardMembership.CanJoin.CanJoinValue,
LastInteractedAt = whiteboardMembership.LastInteractedAt.LastInteractedAtValue
}; };
_context.Add(whiteboardMembershipEntity);
} }
protected override void UpdatePersistenceEntity(WhiteboardMembership persistenceEntity, Domain.Models.WhiteboardMembership.WhiteboardMembership domainEntity)
{
persistenceEntity.IsBanned = domainEntity.IsBanned.IsBannedValue;
persistenceEntity.EditingEnabled = domainEntity.EditingEnabled.EditingEnabledValue;
persistenceEntity.CanJoin = domainEntity.CanJoin.CanJoinValue;
persistenceEntity.LastInteractedAt = domainEntity.LastInteractedAt.LastInteractedAtValue;
} }
} }