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,15 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Commands.CreateNewUserWalletChangeLog;
public record CreateNewUserWalletChangeLogCommand : IRequest<CreateNewUserWalletChangeLogResponseDto>
{
//شناسه کیف پول
public long WalletId { get; init; }
//موجودی
public long CurrentBalance { get; init; }
//تغییر موجودی
public long ChangeValue { get; init; }
//افزایشی؟
public bool IsIncrease { get; init; }
//شناسه ارجاع
public long? RefrenceId { get; init; }
}
@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Commands.CreateNewUserWalletChangeLog;
public class CreateNewUserWalletChangeLogCommandHandler : IRequestHandler<CreateNewUserWalletChangeLogCommand, CreateNewUserWalletChangeLogResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewUserWalletChangeLogCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewUserWalletChangeLogResponseDto> Handle(CreateNewUserWalletChangeLogCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<UserWalletChangeLog>();
await _context.UserWalletChangeLogs.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewUserWalletChangeLogEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewUserWalletChangeLogResponseDto>();
}
}
@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Commands.CreateNewUserWalletChangeLog;
public class CreateNewUserWalletChangeLogCommandValidator : AbstractValidator<CreateNewUserWalletChangeLogCommand>
{
public CreateNewUserWalletChangeLogCommandValidator()
{
RuleFor(model => model.WalletId)
.NotNull();
RuleFor(model => model.CurrentBalance)
.NotNull();
RuleFor(model => model.ChangeValue)
.NotNull();
RuleFor(model => model.IsIncrease)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewUserWalletChangeLogCommand>.CreateWithOptions((CreateNewUserWalletChangeLogCommand)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.UserWalletChangeLogCQ.Commands.CreateNewUserWalletChangeLog;
public class CreateNewUserWalletChangeLogResponseDto
{
//شناسه
public long Id { get; set; }
}
@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Commands.DeleteUserWalletChangeLog;
public record DeleteUserWalletChangeLogCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Commands.DeleteUserWalletChangeLog;
public class DeleteUserWalletChangeLogCommandHandler : IRequestHandler<DeleteUserWalletChangeLogCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeleteUserWalletChangeLogCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteUserWalletChangeLogCommand request, CancellationToken cancellationToken)
{
var entity = await _context.UserWalletChangeLogs
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserWalletChangeLog), request.Id);
entity.IsDeleted = true;
_context.UserWalletChangeLogs.Update(entity);
entity.AddDomainEvent(new DeleteUserWalletChangeLogEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Commands.DeleteUserWalletChangeLog;
public class DeleteUserWalletChangeLogCommandValidator : AbstractValidator<DeleteUserWalletChangeLogCommand>
{
public DeleteUserWalletChangeLogCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeleteUserWalletChangeLogCommand>.CreateWithOptions((DeleteUserWalletChangeLogCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,17 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Commands.UpdateUserWalletChangeLog;
public record UpdateUserWalletChangeLogCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
//شناسه کیف پول
public long WalletId { get; init; }
//موجودی
public long CurrentBalance { get; init; }
//تغییر موجودی
public long ChangeValue { get; init; }
//افزایشی؟
public bool IsIncrease { get; init; }
//شناسه ارجاع
public long? RefrenceId { get; init; }
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Commands.UpdateUserWalletChangeLog;
public class UpdateUserWalletChangeLogCommandHandler : IRequestHandler<UpdateUserWalletChangeLogCommand, Unit>
{
private readonly IApplicationDbContext _context;
public UpdateUserWalletChangeLogCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdateUserWalletChangeLogCommand request, CancellationToken cancellationToken)
{
var entity = await _context.UserWalletChangeLogs
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserWalletChangeLog), request.Id);
request.Adapt(entity);
_context.UserWalletChangeLogs.Update(entity);
entity.AddDomainEvent(new UpdateUserWalletChangeLogEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,24 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Commands.UpdateUserWalletChangeLog;
public class UpdateUserWalletChangeLogCommandValidator : AbstractValidator<UpdateUserWalletChangeLogCommand>
{
public UpdateUserWalletChangeLogCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.WalletId)
.NotNull();
RuleFor(model => model.CurrentBalance)
.NotNull();
RuleFor(model => model.ChangeValue)
.NotNull();
RuleFor(model => model.IsIncrease)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateUserWalletChangeLogCommand>.CreateWithOptions((UpdateUserWalletChangeLogCommand)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.UserWalletChangeLogCQ.EventHandlers;
public class CreateNewUserWalletChangeLogEventHandler : INotificationHandler<CreateNewUserWalletChangeLogEvent>
{
private readonly ILogger<
CreateNewUserWalletChangeLogEventHandler> _logger;
public CreateNewUserWalletChangeLogEventHandler(ILogger<CreateNewUserWalletChangeLogEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewUserWalletChangeLogEvent 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.UserWalletChangeLogCQ.EventHandlers;
public class DeleteUserWalletChangeLogEventHandler : INotificationHandler<DeleteUserWalletChangeLogEvent>
{
private readonly ILogger<
DeleteUserWalletChangeLogEventHandler> _logger;
public DeleteUserWalletChangeLogEventHandler(ILogger<DeleteUserWalletChangeLogEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeleteUserWalletChangeLogEvent 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.UserWalletChangeLogCQ.EventHandlers;
public class UpdateUserWalletChangeLogEventHandler : INotificationHandler<UpdateUserWalletChangeLogEvent>
{
private readonly ILogger<
UpdateUserWalletChangeLogEventHandler> _logger;
public UpdateUserWalletChangeLogEventHandler(ILogger<UpdateUserWalletChangeLogEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdateUserWalletChangeLogEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}
@@ -0,0 +1,25 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Queries.GetAllUserWalletChangeLogByFilter;
public record GetAllUserWalletChangeLogByFilterQuery : IRequest<GetAllUserWalletChangeLogByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllUserWalletChangeLogByFilterFilter? Filter { get; init; }
}public class GetAllUserWalletChangeLogByFilterFilter
{
//شناسه
public long? Id { get; set; }
//شناسه کیف پول
public long? WalletId { get; set; }
//موجودی
public long? CurrentBalance { get; set; }
//تغییر موجودی
public long? ChangeValue { get; set; }
//افزایشی؟
public bool? IsIncrease { get; set; }
//شناسه ارجاع
public long? RefrenceId { get; set; }
}
@@ -0,0 +1,35 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Queries.GetAllUserWalletChangeLogByFilter;
public class GetAllUserWalletChangeLogByFilterQueryHandler : IRequestHandler<GetAllUserWalletChangeLogByFilterQuery, GetAllUserWalletChangeLogByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllUserWalletChangeLogByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllUserWalletChangeLogByFilterResponseDto> Handle(GetAllUserWalletChangeLogByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.UserWalletChangeLogs
.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.WalletId == null || x.WalletId == request.Filter.WalletId)
.Where(x => request.Filter.CurrentBalance == null || x.CurrentBalance == request.Filter.CurrentBalance)
.Where(x => request.Filter.ChangeValue == null || x.ChangeValue == request.Filter.ChangeValue)
.Where(x => request.Filter.IsIncrease == null || x.IsIncrease == request.Filter.IsIncrease)
.Where(x => request.Filter.RefrenceId == null || x.RefrenceId == request.Filter.RefrenceId)
;
}
return new GetAllUserWalletChangeLogByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllUserWalletChangeLogByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}
@@ -0,0 +1,14 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Queries.GetAllUserWalletChangeLogByFilter;
public class GetAllUserWalletChangeLogByFilterQueryValidator : AbstractValidator<GetAllUserWalletChangeLogByFilterQuery>
{
public GetAllUserWalletChangeLogByFilterQueryValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllUserWalletChangeLogByFilterQuery>.CreateWithOptions((GetAllUserWalletChangeLogByFilterQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,23 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Queries.GetAllUserWalletChangeLogByFilter;
public class GetAllUserWalletChangeLogByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllUserWalletChangeLogByFilterResponseModel>? Models { get; set; }
}public class GetAllUserWalletChangeLogByFilterResponseModel
{
//شناسه
public long Id { get; set; }
//شناسه کیف پول
public long WalletId { get; set; }
//موجودی
public long CurrentBalance { get; set; }
//تغییر موجودی
public long ChangeValue { get; set; }
//افزایشی؟
public bool IsIncrease { get; set; }
//شناسه ارجاع
public long? RefrenceId { get; set; }
}
@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Queries.GetUserWalletChangeLog;
public record GetUserWalletChangeLogQuery : IRequest<GetUserWalletChangeLogResponseDto>
{
//شناسه
public long Id { get; init; }
}
@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Queries.GetUserWalletChangeLog;
public class GetUserWalletChangeLogQueryHandler : IRequestHandler<GetUserWalletChangeLogQuery, GetUserWalletChangeLogResponseDto>
{
private readonly IApplicationDbContext _context;
public GetUserWalletChangeLogQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetUserWalletChangeLogResponseDto> Handle(GetUserWalletChangeLogQuery request,
CancellationToken cancellationToken)
{
var response = await _context.UserWalletChangeLogs
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetUserWalletChangeLogResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(UserWalletChangeLog), request.Id);
}
}
@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Queries.GetUserWalletChangeLog;
public class GetUserWalletChangeLogQueryValidator : AbstractValidator<GetUserWalletChangeLogQuery>
{
public GetUserWalletChangeLogQueryValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetUserWalletChangeLogQuery>.CreateWithOptions((GetUserWalletChangeLogQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,17 @@
namespace CMSMicroservice.Application.UserWalletChangeLogCQ.Queries.GetUserWalletChangeLog;
public class GetUserWalletChangeLogResponseDto
{
//شناسه
public long Id { get; set; }
//شناسه کیف پول
public long WalletId { get; set; }
//موجودی
public long CurrentBalance { get; set; }
//تغییر موجودی
public long ChangeValue { get; set; }
//افزایشی؟
public bool IsIncrease { get; set; }
//شناسه ارجاع
public long? RefrenceId { get; set; }
}