Merged AutoMapper branch
This commit is contained in:
@@ -5,7 +5,9 @@ using PyroFetes.Models;
|
|||||||
|
|
||||||
namespace PyroFetes.Endpoints.Deliverers;
|
namespace PyroFetes.Endpoints.Deliverers;
|
||||||
|
|
||||||
public class CreateDelivererEndpoint(PyroFetesDbContext database) : Endpoint<CreateDelivererDto, GetDelivererDto>
|
public class CreateDelivererEndpoint(
|
||||||
|
PyroFetesDbContext database,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<CreateDelivererDto, GetDelivererDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
@@ -20,15 +22,11 @@ public class CreateDelivererEndpoint(PyroFetesDbContext database) : Endpoint<Cre
|
|||||||
{
|
{
|
||||||
Transporter = req.Transporter,
|
Transporter = req.Transporter,
|
||||||
};
|
};
|
||||||
|
|
||||||
database.Deliverers.Add(newDeliverer);
|
database.Deliverers.Add(newDeliverer);
|
||||||
|
|
||||||
await database.SaveChangesAsync(ct);
|
await database.SaveChangesAsync(ct);
|
||||||
|
|
||||||
await Send.OkAsync(new GetDelivererDto()
|
await Send.OkAsync(mapper.Map<GetDelivererDto>(newDeliverer), ct);
|
||||||
{
|
|
||||||
Id = newDeliverer.Id,
|
|
||||||
Transporter = req.Transporter,
|
|
||||||
},ct);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
|
using AutoMapper.QueryableExtensions;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
|
|
||||||
using PyroFetes.DTO.Deliverer.Response;
|
using PyroFetes.DTO.Deliverer.Response;
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Deliverers;
|
namespace PyroFetes.Endpoints.Deliverers;
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ public class GetDelivererRequest
|
|||||||
public int DelivererId { get; set; }
|
public int DelivererId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GetDelivererEndpoint(PyroFetesDbContext database) : Endpoint<GetDelivererRequest, GetDelivererDto>
|
public class GetDelivererEndpoint(
|
||||||
|
PyroFetesDbContext database,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<GetDelivererRequest, GetDelivererDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
@@ -29,11 +31,7 @@ public class GetDelivererEndpoint(PyroFetesDbContext database) : Endpoint<GetDel
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Send.OkAsync(new GetDelivererDto()
|
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
|
||||||
{
|
|
||||||
Id = deliverer.Id,
|
|
||||||
Transporter = deliverer.Transporter,
|
|
||||||
}, ct);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,9 @@ using PyroFetes.Models;
|
|||||||
|
|
||||||
namespace PyroFetes.Endpoints.Deliverers;
|
namespace PyroFetes.Endpoints.Deliverers;
|
||||||
|
|
||||||
public class UpdateDelivererEndpoint(PyroFetesDbContext database) : Endpoint<UpdateDelivererDto, GetDelivererDto>
|
public class UpdateDelivererEndpoint(
|
||||||
|
PyroFetesDbContext database,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<UpdateDelivererDto, GetDelivererDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
@@ -29,11 +31,7 @@ public class UpdateDelivererEndpoint(PyroFetesDbContext database) : Endpoint<Upd
|
|||||||
|
|
||||||
await database.SaveChangesAsync(ct);
|
await database.SaveChangesAsync(ct);
|
||||||
|
|
||||||
await Send.OkAsync(new GetDelivererDto()
|
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
|
||||||
{
|
|
||||||
Id = deliverer.Id,
|
|
||||||
Transporter = deliverer.Transporter,
|
|
||||||
}, ct);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
68
PyroFetes/MappingProfiles/DtoToEntityMappings.cs
Normal file
68
PyroFetes/MappingProfiles/DtoToEntityMappings.cs
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using PyroFetes.DTO.Deliverer.Request;
|
||||||
|
using PyroFetes.DTO.DeliveryNote.Request;
|
||||||
|
using PyroFetes.DTO.Price.Request;
|
||||||
|
using PyroFetes.DTO.Product.Request;
|
||||||
|
using PyroFetes.DTO.ProductDelivery.Request;
|
||||||
|
using PyroFetes.DTO.PurchaseOrder.Request;
|
||||||
|
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||||
|
using PyroFetes.DTO.Quotation.Request;
|
||||||
|
using PyroFetes.DTO.QuotationProduct.Request;
|
||||||
|
using PyroFetes.DTO.SettingDTO.Request;
|
||||||
|
using PyroFetes.DTO.Supplier.Request;
|
||||||
|
using PyroFetes.DTO.User.Request;
|
||||||
|
using PyroFetes.DTO.WareHouseProduct.Request;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
|
namespace PyroFetes.MappingProfiles;
|
||||||
|
|
||||||
|
public class DtoToEntityMappings : Profile
|
||||||
|
{
|
||||||
|
public DtoToEntityMappings()
|
||||||
|
{
|
||||||
|
CreateMap<CreateDelivererDto, Deliverer>();
|
||||||
|
CreateMap<UpdateDelivererDto, Deliverer>();
|
||||||
|
|
||||||
|
CreateMap<CreateDeliveryNoteDto, DeliveryNote>();
|
||||||
|
CreateMap<UpdateDeliveryNoteDto, DeliveryNote>();
|
||||||
|
CreateMap<PatchDeliveryNoteRealDeliveryDateDto, DeliveryNote>();
|
||||||
|
|
||||||
|
CreateMap<CreatePriceDto, Price>();
|
||||||
|
CreateMap<UpdatePriceDto, Price>();
|
||||||
|
CreateMap<PatchPriceSellingPriceDto, Price>();
|
||||||
|
|
||||||
|
CreateMap<CreateProductDto, Product>();
|
||||||
|
CreateMap<UpdateProductDto, Product>();
|
||||||
|
CreateMap<PatchProductMinimalStockDto, Product>();
|
||||||
|
|
||||||
|
CreateMap<CreateProductDeliveryDto, ProductDelivery>();
|
||||||
|
CreateMap<UpdateProductDeliveryDto, ProductDelivery>();
|
||||||
|
|
||||||
|
CreateMap<PatchPurchaseOrderPurchaseConditionsDto,PurchaseOrder>();
|
||||||
|
|
||||||
|
CreateMap<CreatePurchaseProductDto, PurchaseProduct>();
|
||||||
|
CreateMap<UpdatePurchaseProductDto, PurchaseProduct>();
|
||||||
|
CreateMap<PatchPurchaseProductQuantityDto, PurchaseProduct>();
|
||||||
|
|
||||||
|
CreateMap<PatchQuotationConditionsSaleDto, Quotation>();
|
||||||
|
CreateMap<PatchQuotationMessageDto, Quotation>();
|
||||||
|
|
||||||
|
CreateMap<CreateQuotationProductDto, QuotationProduct>();
|
||||||
|
CreateMap<UpdateQuotationProductDto, QuotationProduct>();
|
||||||
|
CreateMap<PatchQuotationProductQuantityDto, QuotationProduct>();
|
||||||
|
|
||||||
|
CreateMap<CreateSettingDto, Setting>();
|
||||||
|
CreateMap<PatchSettingElectronicSignatureDto, Setting>();
|
||||||
|
CreateMap<PatchSettingLogoDto, Setting>();
|
||||||
|
|
||||||
|
CreateMap<CreateSupplierDto, Supplier>();
|
||||||
|
CreateMap<UpdateSupplierDto, Supplier>();
|
||||||
|
CreateMap<PatchSupplierDeliveryDelayDto, Supplier>();
|
||||||
|
|
||||||
|
CreateMap<CreateUserDto, User>();
|
||||||
|
CreateMap<UpdateUserDto, User>();
|
||||||
|
CreateMap<PatchUserPasswordDto, User>();
|
||||||
|
|
||||||
|
CreateMap<PatchWareHouseProductQuantityDto, WarehouseProduct>();
|
||||||
|
}
|
||||||
|
}
|
||||||
46
PyroFetes/MappingProfiles/EntityToDtoMappings.cs
Normal file
46
PyroFetes/MappingProfiles/EntityToDtoMappings.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using PyroFetes.DTO.Deliverer.Response;
|
||||||
|
using PyroFetes.DTO.DeliveryNote.Response;
|
||||||
|
using PyroFetes.DTO.Price.Response;
|
||||||
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
using PyroFetes.DTO.ProductDelivery.Response;
|
||||||
|
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||||
|
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||||
|
using PyroFetes.DTO.Quotation.Response;
|
||||||
|
using PyroFetes.DTO.QuotationProduct.Response;
|
||||||
|
using PyroFetes.DTO.SettingDTO.Response;
|
||||||
|
using PyroFetes.DTO.User.Response;
|
||||||
|
using PyroFetes.DTO.WareHouseProduct.Response;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
|
namespace PyroFetes.MappingProfiles;
|
||||||
|
|
||||||
|
public class EntityToDtoMappings : Profile
|
||||||
|
{
|
||||||
|
public EntityToDtoMappings()
|
||||||
|
{
|
||||||
|
CreateMap<Deliverer, GetDelivererDto>();
|
||||||
|
|
||||||
|
CreateMap<DeliveryNote, GetDeliveryNoteDto>();
|
||||||
|
|
||||||
|
CreateMap<Price, GetPriceDto>();
|
||||||
|
|
||||||
|
CreateMap<Product, GetProductDto>();
|
||||||
|
|
||||||
|
CreateMap<ProductDelivery, GetProductDeliveryDto>();
|
||||||
|
|
||||||
|
CreateMap<PurchaseOrder, GetPurchaseOrderDto>();
|
||||||
|
|
||||||
|
CreateMap<PurchaseProduct, GetPurchaseProductDto>();
|
||||||
|
|
||||||
|
CreateMap<Quotation, GetQuotationDto>();
|
||||||
|
|
||||||
|
CreateMap<QuotationProduct, GetQuotationProductDto>();
|
||||||
|
|
||||||
|
CreateMap<Setting, GetSettingDto>();
|
||||||
|
|
||||||
|
CreateMap<User, GetUserDto>();
|
||||||
|
|
||||||
|
CreateMap<WarehouseProduct, GetWareHouseProductDto>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using AutoMapper.EquivalencyExpression;
|
||||||
using PyroFetes;
|
using PyroFetes;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using FastEndpoints.Swagger;
|
using FastEndpoints.Swagger;
|
||||||
using FastEndpoints.Security;
|
using FastEndpoints.Security;
|
||||||
|
using PyroFetes.MappingProfiles;
|
||||||
|
using IMapper = FastEndpoints.IMapper;
|
||||||
|
|
||||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@@ -15,6 +19,18 @@ builder.Services
|
|||||||
// On ajoute ici la configuration de la base de données
|
// On ajoute ici la configuration de la base de données
|
||||||
builder.Services.AddDbContext<PyroFetesDbContext>();
|
builder.Services.AddDbContext<PyroFetesDbContext>();
|
||||||
|
|
||||||
|
|
||||||
|
MapperConfiguration mappingConfig = new(mc =>
|
||||||
|
{
|
||||||
|
mc.AddCollectionMappers();
|
||||||
|
mc.AddProfile(new DtoToEntityMappings());
|
||||||
|
mc.AddProfile(new EntityToDtoMappings());
|
||||||
|
}, new LoggerFactory());
|
||||||
|
|
||||||
|
|
||||||
|
AutoMapper.IMapper mapper = mappingConfig.CreateMapper();
|
||||||
|
builder.Services.AddSingleton(mapper);
|
||||||
|
|
||||||
// On construit l'application en lui donnant vie
|
// On construit l'application en lui donnant vie
|
||||||
WebApplication app = builder.Build();
|
WebApplication app = builder.Build();
|
||||||
app.UseAuthentication()
|
app.UseAuthentication()
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AutoMapper" Version="15.1.0" />
|
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="9.3.1" />
|
||||||
|
<PackageReference Include="AutoMapper" Version="15.0.1" />
|
||||||
|
<PackageReference Include="AutoMapper.Collection" Version="11.0.0" />
|
||||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||||
<PackageReference Include="FastEndpoints" Version="7.0.1" />
|
<PackageReference Include="FastEndpoints" Version="7.0.1" />
|
||||||
<PackageReference Include="FastEndpoints.Security" Version="7.0.1" />
|
<PackageReference Include="FastEndpoints.Security" Version="7.0.1" />
|
||||||
@@ -20,6 +22,7 @@
|
|||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.20" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.20" />
|
||||||
<PackageReference Include="PasswordGenerator" Version="2.1.0" />
|
<PackageReference Include="PasswordGenerator" Version="2.1.0" />
|
||||||
|
<PackageReference Include="Plainquire.Page" Version="6.5.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
328
PyroFetes/Repositories/PyrofetesRepository.cs
Normal file
328
PyroFetes/Repositories/PyrofetesRepository.cs
Normal file
@@ -0,0 +1,328 @@
|
|||||||
|
using System.Linq.Expressions;
|
||||||
|
using Ardalis.Specification;
|
||||||
|
using Ardalis.Specification.EntityFrameworkCore;
|
||||||
|
using AutoMapper.QueryableExtensions;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Plainquire.Page;
|
||||||
|
|
||||||
|
namespace PyroFetes.Repositories;
|
||||||
|
|
||||||
|
public class PyrofetesRepository<T>(DbContext databaseContext, AutoMapper.IMapper mapper) : RepositoryBase<T>(databaseContext) where T : class
|
||||||
|
{
|
||||||
|
private readonly DbContext _databaseContext = databaseContext;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<T?> FirstOrDefaultAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _databaseContext.Set<T>().AsQueryable().FirstOrDefaultAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<T> FirstAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _databaseContext.Set<T>().AsQueryable().FirstAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="specification"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<T> SingleAsync(ISpecification<T> specification, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await ApplySpecification(specification).SingleAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<T> SingleAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _databaseContext.Set<T>().AsQueryable().SingleAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="specification"></param>
|
||||||
|
/// <param name="selector"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<decimal> SumAsync(
|
||||||
|
ISpecification<T> specification,
|
||||||
|
Expression<Func<T, decimal>> selector,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await ApplySpecification(specification).SumAsync(selector, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
// /// <summary>
|
||||||
|
// ///
|
||||||
|
// /// </summary>
|
||||||
|
// /// <param name="specification"></param>
|
||||||
|
// /// <param name="selector"></param>
|
||||||
|
// /// <param name="cancellationToken"></param>
|
||||||
|
// /// <returns></returns>
|
||||||
|
// public async Task<int> SumAsync(
|
||||||
|
// ISpecification<T> specification,
|
||||||
|
// Expression<Func<T, int>> selector,
|
||||||
|
// CancellationToken cancellationToken = default)
|
||||||
|
// {
|
||||||
|
// return await ApplySpecification(specification).SumAsync(selector, cancellationToken);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="specification"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <param name="postProcessor"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TResult?> ProjectToSingleOrDefaultAsync<TResult>(
|
||||||
|
ISpecification<T> specification,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await ApplySpecification(specification)
|
||||||
|
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||||
|
.SingleOrDefaultAsync(cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="specification"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <param name="postProcessor"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TResult?> ProjectToSingleOrDefaultAsync<TResult>(
|
||||||
|
ISpecification<T> specification,
|
||||||
|
Action<TResult?> postProcessor,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
TResult? result = await ApplySpecification(specification)
|
||||||
|
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||||
|
.SingleOrDefaultAsync(cancellationToken: cancellationToken);
|
||||||
|
postProcessor(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// /// <summary>
|
||||||
|
// ///
|
||||||
|
// /// </summary>
|
||||||
|
// /// <param name="cancellationToken"></param>
|
||||||
|
// /// <typeparam name="TResult"></typeparam>
|
||||||
|
// /// <returns></returns>
|
||||||
|
// public async Task<TResult?> ProjectToSingleOrDefaultAsync<TResult>(
|
||||||
|
// CancellationToken cancellationToken = default)
|
||||||
|
// {
|
||||||
|
// return await _databaseContext.Set<T>().AsQueryable().ProjectTo<TResult>(mapper.ConfigurationProvider).SingleOrDefaultAsync(cancellationToken: cancellationToken);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="specification"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TResult> ProjectToSingleAsync<TResult>(
|
||||||
|
ISpecification<T> specification,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await ApplySpecification(specification)
|
||||||
|
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||||
|
.SingleAsync(cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="specification"></param>
|
||||||
|
/// <param name="postProcessor"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TResult> ProjectToSingleAsync<TResult>(
|
||||||
|
ISpecification<T> specification,
|
||||||
|
Action<TResult?> postProcessor,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
TResult result = await ApplySpecification(specification)
|
||||||
|
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||||
|
.SingleAsync(cancellationToken: cancellationToken);
|
||||||
|
postProcessor(result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<TResult> ProjectToSingleAsync<TResult>(
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _databaseContext.Set<T>()
|
||||||
|
.AsQueryable()
|
||||||
|
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||||
|
.SingleAsync(cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<TResult>> ProjectToListAsync<TResult>(
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _databaseContext.Set<T>()
|
||||||
|
.AsQueryable()
|
||||||
|
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||||
|
.ToListAsync(cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="postProcessor"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<TResult>> ProjectToListAsync<TResult>(
|
||||||
|
Action<List<TResult>> postProcessor,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
List<TResult> results = await _databaseContext.Set<T>()
|
||||||
|
.AsQueryable()
|
||||||
|
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||||
|
.ToListAsync(cancellationToken: cancellationToken);
|
||||||
|
postProcessor(results);
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="specification"></param>
|
||||||
|
/// <param name="postProcessor"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<TResult>> ProjectToListAsync<TResult>(
|
||||||
|
ISpecification<T> specification,
|
||||||
|
Action<List<TResult>> postProcessor,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
List<TResult> results = await ApplySpecification(specification)
|
||||||
|
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||||
|
.ToListAsync(cancellationToken: cancellationToken);
|
||||||
|
postProcessor(results);
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="specification"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<TResult>> ProjectToListAsync<TResult>(
|
||||||
|
ISpecification<T> specification,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await ApplySpecification(specification)
|
||||||
|
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||||
|
.ToListAsync(cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="specification"></param>
|
||||||
|
/// <param name="page"></param>
|
||||||
|
/// <param name="postProcessor"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<TResult>> ProjectToListAsync<TResult>(
|
||||||
|
ISpecification<T> specification,
|
||||||
|
EntityPage page,
|
||||||
|
Action<List<TResult>> postProcessor,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
List<TResult> results = await ApplySpecification(specification)
|
||||||
|
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||||
|
.Page(page)
|
||||||
|
.ToListAsync(cancellationToken: cancellationToken);
|
||||||
|
postProcessor(results);
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="specification"></param>
|
||||||
|
/// <param name="page"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<TResult>> ProjectToListAsync<TResult>(
|
||||||
|
ISpecification<T> specification,
|
||||||
|
EntityPage page,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await ApplySpecification(specification)
|
||||||
|
.ProjectTo<TResult>(mapper.ConfigurationProvider)
|
||||||
|
.Page(page)
|
||||||
|
.ToListAsync(cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="specification"></param>
|
||||||
|
/// <param name="selector"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<TResult>> SelectManyAsync<TResult>(
|
||||||
|
ISpecification<T> specification,
|
||||||
|
Expression<Func<T, IEnumerable<TResult>>> selector,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await ApplySpecification(specification).SelectMany(selector).ToListAsync(cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="specification"></param>
|
||||||
|
/// <param name="selector"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <typeparam name="TResult"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<TResult>> SelectAsync<TResult>(
|
||||||
|
ISpecification<T> specification,
|
||||||
|
Expression<Func<T, TResult>> selector,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await ApplySpecification(specification).Select(selector).ToListAsync(cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user