Generator Changes at 11/12/2025 1:32:03 AM +03:30
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
namespace CMSMicroservice.Application.FactorDetailsCQ.Queries.GetAllFactorDetailsByFilter;
|
||||
public record GetAllFactorDetailsByFilterQuery : IRequest<GetAllFactorDetailsByFilterResponseDto>
|
||||
{
|
||||
//موقعیت صفحه بندی
|
||||
public PaginationState? PaginationState { get; init; }
|
||||
//مرتب سازی بر اساس
|
||||
public string? SortBy { get; init; }
|
||||
//فیلتر
|
||||
public GetAllFactorDetailsByFilterFilter? Filter { get; init; }
|
||||
|
||||
}public class GetAllFactorDetailsByFilterFilter
|
||||
{
|
||||
//
|
||||
public long? Id { get; set; }
|
||||
//
|
||||
public long? ProductId { get; set; }
|
||||
//
|
||||
public int? Count { get; set; }
|
||||
//
|
||||
public long? UnitPrice { get; set; }
|
||||
//
|
||||
public int? UnitDiscount { get; set; }
|
||||
//
|
||||
public long? OrderId { get; set; }
|
||||
//
|
||||
public long? UnitDiscountPrice { get; set; }
|
||||
//
|
||||
public bool? IsChangePrice { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
namespace CMSMicroservice.Application.FactorDetailsCQ.Queries.GetAllFactorDetailsByFilter;
|
||||
public class GetAllFactorDetailsByFilterQueryHandler : IRequestHandler<GetAllFactorDetailsByFilterQuery, GetAllFactorDetailsByFilterResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetAllFactorDetailsByFilterQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetAllFactorDetailsByFilterResponseDto> Handle(GetAllFactorDetailsByFilterQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context.FactorDetailss
|
||||
.ApplyOrder(sortBy: request.SortBy)
|
||||
.AsNoTracking()
|
||||
.AsQueryable();
|
||||
if (request.Filter is not null)
|
||||
{
|
||||
query = query
|
||||
.Where(x => request.Filter.Id == null || x.Id == request.Filter.Id)
|
||||
.Where(x => request.Filter.ProductId == null || x.ProductId == request.Filter.ProductId)
|
||||
.Where(x => request.Filter.Count == null || x.Count == request.Filter.Count)
|
||||
.Where(x => request.Filter.UnitPrice == null || x.UnitPrice == request.Filter.UnitPrice)
|
||||
.Where(x => request.Filter.UnitDiscount == null || x.UnitDiscount == request.Filter.UnitDiscount)
|
||||
.Where(x => request.Filter.OrderId == null || x.OrderId == request.Filter.OrderId)
|
||||
.Where(x => request.Filter.UnitDiscountPrice == null || x.UnitDiscountPrice == request.Filter.UnitDiscountPrice)
|
||||
.Where(x => request.Filter.IsChangePrice == null || x.IsChangePrice == request.Filter.IsChangePrice)
|
||||
;
|
||||
}
|
||||
return new GetAllFactorDetailsByFilterResponseDto
|
||||
{
|
||||
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
|
||||
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
|
||||
.ProjectToType<GetAllFactorDetailsByFilterResponseModel>().ToListAsync(cancellationToken)
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace CMSMicroservice.Application.FactorDetailsCQ.Queries.GetAllFactorDetailsByFilter;
|
||||
public class GetAllFactorDetailsByFilterQueryValidator : AbstractValidator<GetAllFactorDetailsByFilterQuery>
|
||||
{
|
||||
public GetAllFactorDetailsByFilterQueryValidator()
|
||||
{
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<GetAllFactorDetailsByFilterQuery>.CreateWithOptions((GetAllFactorDetailsByFilterQuery)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace CMSMicroservice.Application.FactorDetailsCQ.Queries.GetAllFactorDetailsByFilter;
|
||||
public class GetAllFactorDetailsByFilterResponseDto
|
||||
{
|
||||
//متادیتا
|
||||
public MetaData MetaData { get; set; }
|
||||
//مدل خروجی
|
||||
public List<GetAllFactorDetailsByFilterResponseModel>? Models { get; set; }
|
||||
|
||||
}public class GetAllFactorDetailsByFilterResponseModel
|
||||
{
|
||||
//
|
||||
public long Id { get; set; }
|
||||
//
|
||||
public long ProductId { get; set; }
|
||||
//
|
||||
public int Count { get; set; }
|
||||
//
|
||||
public long UnitPrice { get; set; }
|
||||
//
|
||||
public int UnitDiscount { get; set; }
|
||||
//
|
||||
public long OrderId { get; set; }
|
||||
//
|
||||
public long UnitDiscountPrice { get; set; }
|
||||
//
|
||||
public bool IsChangePrice { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace CMSMicroservice.Application.FactorDetailsCQ.Queries.GetFactorDetails;
|
||||
public record GetFactorDetailsQuery : IRequest<GetFactorDetailsResponseDto>
|
||||
{
|
||||
//
|
||||
public long Id { get; init; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace CMSMicroservice.Application.FactorDetailsCQ.Queries.GetFactorDetails;
|
||||
public class GetFactorDetailsQueryHandler : IRequestHandler<GetFactorDetailsQuery, GetFactorDetailsResponseDto>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
|
||||
public GetFactorDetailsQueryHandler(IApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetFactorDetailsResponseDto> Handle(GetFactorDetailsQuery request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _context.FactorDetailss
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.ProjectToType<GetFactorDetailsResponseDto>()
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
return response ?? throw new NotFoundException(nameof(FactorDetails), request.Id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace CMSMicroservice.Application.FactorDetailsCQ.Queries.GetFactorDetails;
|
||||
public class GetFactorDetailsQueryValidator : AbstractValidator<GetFactorDetailsQuery>
|
||||
{
|
||||
public GetFactorDetailsQueryValidator()
|
||||
{
|
||||
RuleFor(model => model.Id)
|
||||
.NotNull();
|
||||
}
|
||||
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||
{
|
||||
var result = await ValidateAsync(ValidationContext<GetFactorDetailsQuery>.CreateWithOptions((GetFactorDetailsQuery)model, x => x.IncludeProperties(propertyName)));
|
||||
if (result.IsValid)
|
||||
return Array.Empty<string>();
|
||||
return result.Errors.Select(e => e.ErrorMessage);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace CMSMicroservice.Application.FactorDetailsCQ.Queries.GetFactorDetails;
|
||||
public class GetFactorDetailsResponseDto
|
||||
{
|
||||
//
|
||||
public long Id { get; set; }
|
||||
//
|
||||
public long ProductId { get; set; }
|
||||
//
|
||||
public int Count { get; set; }
|
||||
//
|
||||
public long UnitPrice { get; set; }
|
||||
//
|
||||
public int UnitDiscount { get; set; }
|
||||
//
|
||||
public long OrderId { get; set; }
|
||||
//
|
||||
public long UnitDiscountPrice { get; set; }
|
||||
//
|
||||
public bool IsChangePrice { get; set; }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user