This commit reorganizes namespaces from `DigitalData.Core.Abstractions` and `DigitalData.Core.DTO` to `DigitalData.Core.Application.Interfaces` and `DigitalData.Core.Application.DTO`, improving maintainability and clarity. Updated using directives across multiple files to reflect the new structure, ensuring functionality remains intact. Project references in `DigitalData.Core.API.csproj` have been consolidated to include the new Application project. Introduced new classes and interfaces such as `BaseDTO`, `CookieConsentSettings`, `DataResult`, `Notice`, and `Result` to enhance data transfer and service result handling. Updated `IRepository`, `ICRUDRepository`, and `IEntityMapper` interfaces to facilitate CRUD operations and entity mapping. Added extension methods in `Extensions.cs` to improve repository usability. New interfaces for HTTP client services have been added, enhancing external API call handling. Overall, these changes reflect a significant restructuring aimed at improving organization and preparing for future development.
35 lines
1.6 KiB
C#
35 lines
1.6 KiB
C#
using System.Linq.Expressions;
|
|
|
|
namespace DigitalData.Core.Application.Interfaces.Repository;
|
|
|
|
public static class Extensions
|
|
{
|
|
#region Create
|
|
public static Task<TEntity> CreateAsync<TEntity, TDto>(this IRepository<TEntity> repository, TDto dto, CancellationToken ct = default)
|
|
{
|
|
var entity = repository.Mapper.Map(dto);
|
|
return repository.CreateAsync(entity, ct);
|
|
}
|
|
|
|
public static Task<IEnumerable<TEntity>> CreateAsync<TEntity, TDto>(this IRepository<TEntity> repository, IEnumerable<TDto> dtos, CancellationToken ct = default)
|
|
{
|
|
var entities = dtos.Select(dto => repository.Mapper.Map(dto));
|
|
return repository.CreateAsync(entities, ct);
|
|
}
|
|
#endregion
|
|
|
|
#region Read
|
|
public static async Task<TEntity?> ReadFirstOrDefaultAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
|
|
=> (await repository.ReadAllAsync(expression)).FirstOrDefault();
|
|
|
|
public static async Task<TEntity> ReadFirstAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
|
|
=> (await repository.ReadAllAsync(expression)).First();
|
|
|
|
public static async Task<TEntity?> ReadSingleOrDefaultAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
|
|
=> (await repository.ReadAllAsync(expression)).SingleOrDefault();
|
|
|
|
public static async Task<TEntity> ReadSingleAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
|
|
=> (await repository.ReadAllAsync(expression)).Single();
|
|
#endregion
|
|
}
|