From 6916e169b17fc22997f3fed178863f2e1ed5d059 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Thu, 17 Apr 2025 13:01:51 +0200 Subject: [PATCH] Add mapping methods to IRepository and DbRepository Updated the `IRepository` interface to include two new mapping methods: `Map(TSource source)` and `Map(TEntity source)`. Implemented these methods in the `DbRepository` class, utilizing a `Mapper` for conversions between source types and entity types, as well as between entity types and DTOs. --- DigitalData.Core.Abstractions/Infrastructure/IRepository.cs | 4 ++++ DigitalData.Core.Infrastructure/DbRepository.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/DigitalData.Core.Abstractions/Infrastructure/IRepository.cs b/DigitalData.Core.Abstractions/Infrastructure/IRepository.cs index 5d748bc..18c5e70 100644 --- a/DigitalData.Core.Abstractions/Infrastructure/IRepository.cs +++ b/DigitalData.Core.Abstractions/Infrastructure/IRepository.cs @@ -13,4 +13,8 @@ public interface IRepository public Task UpdateAsync(TUpdate update, Expression> expression, CancellationToken ct = default); public Task DeleteAsync(Expression> expression, CancellationToken ct = default); + + public TEntity Map(TSource source); + + public TDto Map(TEntity source); } diff --git a/DigitalData.Core.Infrastructure/DbRepository.cs b/DigitalData.Core.Infrastructure/DbRepository.cs index 67b4480..59aba31 100644 --- a/DigitalData.Core.Infrastructure/DbRepository.cs +++ b/DigitalData.Core.Infrastructure/DbRepository.cs @@ -63,4 +63,8 @@ public class DbRepository : IRepository where TDbC await Context.SaveChangesAsync(ct); } + + public TEntity Map(TSource source) => Mapper.Map(source); + + public TDto Map(TEntity entity) => Mapper.Map(entity); }