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
@@ -0,0 +1,47 @@
namespace CMSMicroservice.Application.TransactionsCQ.Commands.CreateNewTransactions;
public record CreateNewTransactionsCommand : IRequest<CreateNewTransactionsResponseDto>
{
//
public string MerchantId { get; init; }
//
public long Amount { get; init; }
//
public string CallbackUrl { get; init; }
//
public string Description { get; init; }
//
public string? Mobile { get; init; }
//
public string? Email { get; init; }
//
public int? RequestStatusCode { get; init; }
//
public string? RequestStatusMessage { get; init; }
//
public string? Authority { get; init; }
//
public string? FeeType { get; init; }
//
public long? Fee { get; init; }
//
public int? Currency { get; init; }
//
public PaymentStatus PaymentStatus { get; init; }
//تاریخ پرداخت
public DateTime? PaymentDate { get; init; }
//
public int? VerificationStatusCode { get; init; }
//
public string? VerificationStatusMessage { get; init; }
//
public string? CardHash { get; init; }
//
public string? CardPan { get; init; }
//
public string? RefId { get; init; }
//
public string? OrderId { get; init; }
//
public TransactionType Type { get; init; }
}
@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.TransactionsCQ.Commands.CreateNewTransactions;
public class CreateNewTransactionsCommandHandler : IRequestHandler<CreateNewTransactionsCommand, CreateNewTransactionsResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewTransactionsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewTransactionsResponseDto> Handle(CreateNewTransactionsCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<Transactions>();
await _context.Transactionss.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewTransactionsEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewTransactionsResponseDto>();
}
}
@@ -0,0 +1,28 @@
namespace CMSMicroservice.Application.TransactionsCQ.Commands.CreateNewTransactions;
public class CreateNewTransactionsCommandValidator : AbstractValidator<CreateNewTransactionsCommand>
{
public CreateNewTransactionsCommandValidator()
{
RuleFor(model => model.MerchantId)
.NotEmpty();
RuleFor(model => model.Amount)
.NotNull();
RuleFor(model => model.CallbackUrl)
.NotEmpty();
RuleFor(model => model.Description)
.NotEmpty();
RuleFor(model => model.PaymentStatus)
.IsInEnum()
.NotNull();
RuleFor(model => model.Type)
.IsInEnum()
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewTransactionsCommand>.CreateWithOptions((CreateNewTransactionsCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.TransactionsCQ.Commands.CreateNewTransactions;
public class CreateNewTransactionsResponseDto
{
//
public long Id { get; set; }
}
@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.TransactionsCQ.Commands.DeleteTransactions;
public record DeleteTransactionsCommand : IRequest<Unit>
{
//
public long Id { get; init; }
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.TransactionsCQ.Commands.DeleteTransactions;
public class DeleteTransactionsCommandHandler : IRequestHandler<DeleteTransactionsCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeleteTransactionsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteTransactionsCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Transactionss
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(Transactions), request.Id);
entity.IsDeleted = true;
_context.Transactionss.Update(entity);
entity.AddDomainEvent(new DeleteTransactionsEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.TransactionsCQ.Commands.DeleteTransactions;
public class DeleteTransactionsCommandValidator : AbstractValidator<DeleteTransactionsCommand>
{
public DeleteTransactionsCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeleteTransactionsCommand>.CreateWithOptions((DeleteTransactionsCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,49 @@
namespace CMSMicroservice.Application.TransactionsCQ.Commands.UpdateTransactions;
public record UpdateTransactionsCommand : IRequest<Unit>
{
//
public long Id { get; init; }
//
public string MerchantId { get; init; }
//
public long Amount { get; init; }
//
public string CallbackUrl { get; init; }
//
public string Description { get; init; }
//
public string? Mobile { get; init; }
//
public string? Email { get; init; }
//
public int? RequestStatusCode { get; init; }
//
public string? RequestStatusMessage { get; init; }
//
public string? Authority { get; init; }
//
public string? FeeType { get; init; }
//
public long? Fee { get; init; }
//
public int? Currency { get; init; }
//
public PaymentStatus PaymentStatus { get; init; }
//تاریخ پرداخت
public DateTime? PaymentDate { get; init; }
//
public int? VerificationStatusCode { get; init; }
//
public string? VerificationStatusMessage { get; init; }
//
public string? CardHash { get; init; }
//
public string? CardPan { get; init; }
//
public string? RefId { get; init; }
//
public string? OrderId { get; init; }
//
public TransactionType Type { get; init; }
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.TransactionsCQ.Commands.UpdateTransactions;
public class UpdateTransactionsCommandHandler : IRequestHandler<UpdateTransactionsCommand, Unit>
{
private readonly IApplicationDbContext _context;
public UpdateTransactionsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdateTransactionsCommand request, CancellationToken cancellationToken)
{
var entity = await _context.Transactionss
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(Transactions), request.Id);
request.Adapt(entity);
_context.Transactionss.Update(entity);
entity.AddDomainEvent(new UpdateTransactionsEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,30 @@
namespace CMSMicroservice.Application.TransactionsCQ.Commands.UpdateTransactions;
public class UpdateTransactionsCommandValidator : AbstractValidator<UpdateTransactionsCommand>
{
public UpdateTransactionsCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.MerchantId)
.NotEmpty();
RuleFor(model => model.Amount)
.NotNull();
RuleFor(model => model.CallbackUrl)
.NotEmpty();
RuleFor(model => model.Description)
.NotEmpty();
RuleFor(model => model.PaymentStatus)
.IsInEnum()
.NotNull();
RuleFor(model => model.Type)
.IsInEnum()
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateTransactionsCommand>.CreateWithOptions((UpdateTransactionsCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.TransactionsCQ.EventHandlers;
public class CreateNewTransactionsEventHandler : INotificationHandler<CreateNewTransactionsEvent>
{
private readonly ILogger<
CreateNewTransactionsEventHandler> _logger;
public CreateNewTransactionsEventHandler(ILogger<CreateNewTransactionsEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewTransactionsEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.TransactionsCQ.EventHandlers;
public class DeleteTransactionsEventHandler : INotificationHandler<DeleteTransactionsEvent>
{
private readonly ILogger<
DeleteTransactionsEventHandler> _logger;
public DeleteTransactionsEventHandler(ILogger<DeleteTransactionsEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeleteTransactionsEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.TransactionsCQ.EventHandlers;
public class UpdateTransactionsEventHandler : INotificationHandler<UpdateTransactionsEvent>
{
private readonly ILogger<
UpdateTransactionsEventHandler> _logger;
public UpdateTransactionsEventHandler(ILogger<UpdateTransactionsEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdateTransactionsEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}
@@ -0,0 +1,57 @@
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetAllTransactionsByFilter;
public record GetAllTransactionsByFilterQuery : IRequest<GetAllTransactionsByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllTransactionsByFilterFilter? Filter { get; init; }
}public class GetAllTransactionsByFilterFilter
{
//
public long? Id { get; set; }
//
public string? MerchantId { get; set; }
//
public long? Amount { get; set; }
//
public string? CallbackUrl { get; set; }
//
public string? Description { get; set; }
//
public string? Mobile { get; set; }
//
public string? Email { get; set; }
//
public int? RequestStatusCode { get; set; }
//
public string? RequestStatusMessage { get; set; }
//
public string? Authority { get; set; }
//
public string? FeeType { get; set; }
//
public long? Fee { get; set; }
//
public int? Currency { get; set; }
//
public PaymentStatus? PaymentStatus { get; set; }
//تاریخ پرداخت
public DateTime? PaymentDate { get; set; }
//
public int? VerificationStatusCode { get; set; }
//
public string? VerificationStatusMessage { get; set; }
//
public string? CardHash { get; set; }
//
public string? CardPan { get; set; }
//
public string? RefId { get; set; }
//
public string? OrderId { get; set; }
//
public TransactionType? Type { get; set; }
}
@@ -0,0 +1,51 @@
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetAllTransactionsByFilter;
public class GetAllTransactionsByFilterQueryHandler : IRequestHandler<GetAllTransactionsByFilterQuery, GetAllTransactionsByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllTransactionsByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllTransactionsByFilterResponseDto> Handle(GetAllTransactionsByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.Transactionss
.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.MerchantId == null || x.MerchantId.Contains(request.Filter.MerchantId))
.Where(x => request.Filter.Amount == null || x.Amount == request.Filter.Amount)
.Where(x => request.Filter.CallbackUrl == null || x.CallbackUrl.Contains(request.Filter.CallbackUrl))
.Where(x => request.Filter.Description == null || x.Description.Contains(request.Filter.Description))
.Where(x => request.Filter.Mobile == null || x.Mobile.Contains(request.Filter.Mobile))
.Where(x => request.Filter.Email == null || x.Email.Contains(request.Filter.Email))
.Where(x => request.Filter.RequestStatusCode == null || x.RequestStatusCode == request.Filter.RequestStatusCode)
.Where(x => request.Filter.RequestStatusMessage == null || x.RequestStatusMessage.Contains(request.Filter.RequestStatusMessage))
.Where(x => request.Filter.Authority == null || x.Authority.Contains(request.Filter.Authority))
.Where(x => request.Filter.FeeType == null || x.FeeType.Contains(request.Filter.FeeType))
.Where(x => request.Filter.Fee == null || x.Fee == request.Filter.Fee)
.Where(x => request.Filter.Currency == null || x.Currency == request.Filter.Currency)
.Where(x => request.Filter.PaymentStatus == null || x.PaymentStatus == request.Filter.PaymentStatus)
.Where(x => request.Filter.PaymentDate == null || x.PaymentDate == request.Filter.PaymentDate)
.Where(x => request.Filter.VerificationStatusCode == null || x.VerificationStatusCode == request.Filter.VerificationStatusCode)
.Where(x => request.Filter.VerificationStatusMessage == null || x.VerificationStatusMessage.Contains(request.Filter.VerificationStatusMessage))
.Where(x => request.Filter.CardHash == null || x.CardHash.Contains(request.Filter.CardHash))
.Where(x => request.Filter.CardPan == null || x.CardPan.Contains(request.Filter.CardPan))
.Where(x => request.Filter.RefId == null || x.RefId.Contains(request.Filter.RefId))
.Where(x => request.Filter.OrderId == null || x.OrderId.Contains(request.Filter.OrderId))
.Where(x => request.Filter.Type == null || x.Type == request.Filter.Type)
;
}
return new GetAllTransactionsByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllTransactionsByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}
@@ -0,0 +1,14 @@
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetAllTransactionsByFilter;
public class GetAllTransactionsByFilterQueryValidator : AbstractValidator<GetAllTransactionsByFilterQuery>
{
public GetAllTransactionsByFilterQueryValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllTransactionsByFilterQuery>.CreateWithOptions((GetAllTransactionsByFilterQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,55 @@
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetAllTransactionsByFilter;
public class GetAllTransactionsByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllTransactionsByFilterResponseModel>? Models { get; set; }
}public class GetAllTransactionsByFilterResponseModel
{
//
public long Id { get; set; }
//
public string MerchantId { get; set; }
//
public long Amount { get; set; }
//
public string CallbackUrl { get; set; }
//
public string Description { get; set; }
//
public string? Mobile { get; set; }
//
public string? Email { get; set; }
//
public int? RequestStatusCode { get; set; }
//
public string? RequestStatusMessage { get; set; }
//
public string? Authority { get; set; }
//
public string? FeeType { get; set; }
//
public long? Fee { get; set; }
//
public int? Currency { get; set; }
//
public PaymentStatus PaymentStatus { get; set; }
//تاریخ پرداخت
public DateTime? PaymentDate { get; set; }
//
public int? VerificationStatusCode { get; set; }
//
public string? VerificationStatusMessage { get; set; }
//
public string? CardHash { get; set; }
//
public string? CardPan { get; set; }
//
public string? RefId { get; set; }
//
public string? OrderId { get; set; }
//
public TransactionType Type { get; set; }
}
@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetTransactions;
public record GetTransactionsQuery : IRequest<GetTransactionsResponseDto>
{
//
public long Id { get; init; }
}
@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetTransactions;
public class GetTransactionsQueryHandler : IRequestHandler<GetTransactionsQuery, GetTransactionsResponseDto>
{
private readonly IApplicationDbContext _context;
public GetTransactionsQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetTransactionsResponseDto> Handle(GetTransactionsQuery request,
CancellationToken cancellationToken)
{
var response = await _context.Transactionss
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetTransactionsResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(Transactions), request.Id);
}
}
@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetTransactions;
public class GetTransactionsQueryValidator : AbstractValidator<GetTransactionsQuery>
{
public GetTransactionsQueryValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetTransactionsQuery>.CreateWithOptions((GetTransactionsQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,49 @@
namespace CMSMicroservice.Application.TransactionsCQ.Queries.GetTransactions;
public class GetTransactionsResponseDto
{
//
public long Id { get; set; }
//
public string MerchantId { get; set; }
//
public long Amount { get; set; }
//
public string CallbackUrl { get; set; }
//
public string Description { get; set; }
//
public string? Mobile { get; set; }
//
public string? Email { get; set; }
//
public int? RequestStatusCode { get; set; }
//
public string? RequestStatusMessage { get; set; }
//
public string? Authority { get; set; }
//
public string? FeeType { get; set; }
//
public long? Fee { get; set; }
//
public int? Currency { get; set; }
//
public PaymentStatus PaymentStatus { get; set; }
//تاریخ پرداخت
public DateTime? PaymentDate { get; set; }
//
public int? VerificationStatusCode { get; set; }
//
public string? VerificationStatusMessage { get; set; }
//
public string? CardHash { get; set; }
//
public string? CardPan { get; set; }
//
public string? RefId { get; set; }
//
public string? OrderId { get; set; }
//
public TransactionType Type { get; set; }
}