Generator Changes at 11/12/2025 1:32:03 AM +03:30

This commit is contained in:
masoodafar-web
2025-11-12 02:24:02 +03:30
parent 826ae4589f
commit b27c765731
290 changed files with 30811 additions and 21316 deletions

View File

@@ -0,0 +1,19 @@
namespace CMSMicroservice.Application.FactorDetailsCQ.Commands.CreateNewFactorDetails;
public record CreateNewFactorDetailsCommand : IRequest<CreateNewFactorDetailsResponseDto>
{
//
public long ProductId { get; init; }
//
public int Count { get; init; }
//
public long UnitPrice { get; init; }
//
public int UnitDiscount { get; init; }
//
public long OrderId { get; init; }
//
public long UnitDiscountPrice { get; init; }
//
public bool IsChangePrice { get; init; }
}

View File

@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.FactorDetailsCQ.Commands.CreateNewFactorDetails;
public class CreateNewFactorDetailsCommandHandler : IRequestHandler<CreateNewFactorDetailsCommand, CreateNewFactorDetailsResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewFactorDetailsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewFactorDetailsResponseDto> Handle(CreateNewFactorDetailsCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<FactorDetails>();
await _context.FactorDetailss.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewFactorDetailsEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewFactorDetailsResponseDto>();
}
}

View File

@@ -0,0 +1,28 @@
namespace CMSMicroservice.Application.FactorDetailsCQ.Commands.CreateNewFactorDetails;
public class CreateNewFactorDetailsCommandValidator : AbstractValidator<CreateNewFactorDetailsCommand>
{
public CreateNewFactorDetailsCommandValidator()
{
RuleFor(model => model.ProductId)
.NotNull();
RuleFor(model => model.Count)
.NotNull();
RuleFor(model => model.UnitPrice)
.NotNull();
RuleFor(model => model.UnitDiscount)
.NotNull();
RuleFor(model => model.OrderId)
.NotNull();
RuleFor(model => model.UnitDiscountPrice)
.NotNull();
RuleFor(model => model.IsChangePrice)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewFactorDetailsCommand>.CreateWithOptions((CreateNewFactorDetailsCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.FactorDetailsCQ.Commands.CreateNewFactorDetails;
public class CreateNewFactorDetailsResponseDto
{
//
public long Id { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.FactorDetailsCQ.Commands.DeleteFactorDetails;
public record DeleteFactorDetailsCommand : IRequest<Unit>
{
//
public long Id { get; init; }
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.FactorDetailsCQ.Commands.DeleteFactorDetails;
public class DeleteFactorDetailsCommandHandler : IRequestHandler<DeleteFactorDetailsCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeleteFactorDetailsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteFactorDetailsCommand request, CancellationToken cancellationToken)
{
var entity = await _context.FactorDetailss
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(FactorDetails), request.Id);
entity.IsDeleted = true;
_context.FactorDetailss.Update(entity);
entity.AddDomainEvent(new DeleteFactorDetailsEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}

View File

@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.FactorDetailsCQ.Commands.DeleteFactorDetails;
public class DeleteFactorDetailsCommandValidator : AbstractValidator<DeleteFactorDetailsCommand>
{
public DeleteFactorDetailsCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeleteFactorDetailsCommand>.CreateWithOptions((DeleteFactorDetailsCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,21 @@
namespace CMSMicroservice.Application.FactorDetailsCQ.Commands.UpdateFactorDetails;
public record UpdateFactorDetailsCommand : IRequest<Unit>
{
//
public long Id { get; init; }
//
public long ProductId { get; init; }
//
public int Count { get; init; }
//
public long UnitPrice { get; init; }
//
public int UnitDiscount { get; init; }
//
public long OrderId { get; init; }
//
public long UnitDiscountPrice { get; init; }
//
public bool IsChangePrice { get; init; }
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.FactorDetailsCQ.Commands.UpdateFactorDetails;
public class UpdateFactorDetailsCommandHandler : IRequestHandler<UpdateFactorDetailsCommand, Unit>
{
private readonly IApplicationDbContext _context;
public UpdateFactorDetailsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdateFactorDetailsCommand request, CancellationToken cancellationToken)
{
var entity = await _context.FactorDetailss
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(FactorDetails), request.Id);
request.Adapt(entity);
_context.FactorDetailss.Update(entity);
entity.AddDomainEvent(new UpdateFactorDetailsEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}

View File

@@ -0,0 +1,30 @@
namespace CMSMicroservice.Application.FactorDetailsCQ.Commands.UpdateFactorDetails;
public class UpdateFactorDetailsCommandValidator : AbstractValidator<UpdateFactorDetailsCommand>
{
public UpdateFactorDetailsCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.ProductId)
.NotNull();
RuleFor(model => model.Count)
.NotNull();
RuleFor(model => model.UnitPrice)
.NotNull();
RuleFor(model => model.UnitDiscount)
.NotNull();
RuleFor(model => model.OrderId)
.NotNull();
RuleFor(model => model.UnitDiscountPrice)
.NotNull();
RuleFor(model => model.IsChangePrice)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateFactorDetailsCommand>.CreateWithOptions((UpdateFactorDetailsCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.FactorDetailsCQ.EventHandlers;
public class CreateNewFactorDetailsEventHandler : INotificationHandler<CreateNewFactorDetailsEvent>
{
private readonly ILogger<
CreateNewFactorDetailsEventHandler> _logger;
public CreateNewFactorDetailsEventHandler(ILogger<CreateNewFactorDetailsEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewFactorDetailsEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.FactorDetailsCQ.EventHandlers;
public class DeleteFactorDetailsEventHandler : INotificationHandler<DeleteFactorDetailsEvent>
{
private readonly ILogger<
DeleteFactorDetailsEventHandler> _logger;
public DeleteFactorDetailsEventHandler(ILogger<DeleteFactorDetailsEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeleteFactorDetailsEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.FactorDetailsCQ.EventHandlers;
public class UpdateFactorDetailsEventHandler : INotificationHandler<UpdateFactorDetailsEvent>
{
private readonly ILogger<
UpdateFactorDetailsEventHandler> _logger;
public UpdateFactorDetailsEventHandler(ILogger<UpdateFactorDetailsEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdateFactorDetailsEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -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; }
}

View File

@@ -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)
};
}
}

View File

@@ -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);
};
}

View File

@@ -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; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.FactorDetailsCQ.Queries.GetFactorDetails;
public record GetFactorDetailsQuery : IRequest<GetFactorDetailsResponseDto>
{
//
public long Id { get; init; }
}

View File

@@ -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);
}
}

View File

@@ -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);
};
}

View File

@@ -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; }
}