Generator Changes at 9/27/2025 8:46:36 AM

This commit is contained in:
generator
2025-09-27 08:46:36 +03:30
parent fd82e3edcf
commit fd8614f72e
261 changed files with 6333 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
namespace CMSMicroservice.Application.UserRoleCQ.Commands.CreateNewUserRole;
public record CreateNewUserRoleCommand : IRequest<CreateNewUserRoleResponseDto>
{
//شناسه نقش
public long RoleId { get; init; }
//شناسه کاربر
public long UserId { get; init; }
}

View File

@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.UserRoleCQ.Commands.CreateNewUserRole;
public class CreateNewUserRoleCommandHandler : IRequestHandler<CreateNewUserRoleCommand, CreateNewUserRoleResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewUserRoleCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewUserRoleResponseDto> Handle(CreateNewUserRoleCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<UserRole>();
await _context.UserRoles.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewUserRoleEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewUserRoleResponseDto>();
}
}

View File

@@ -0,0 +1,18 @@
namespace CMSMicroservice.Application.UserRoleCQ.Commands.CreateNewUserRole;
public class CreateNewUserRoleCommandValidator : AbstractValidator<CreateNewUserRoleCommand>
{
public CreateNewUserRoleCommandValidator()
{
RuleFor(model => model.RoleId)
.NotNull();
RuleFor(model => model.UserId)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewUserRoleCommand>.CreateWithOptions((CreateNewUserRoleCommand)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.UserRoleCQ.Commands.CreateNewUserRole;
public class CreateNewUserRoleResponseDto
{
//شناسه
public long Id { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.UserRoleCQ.Commands.DeleteUserRole;
public record DeleteUserRoleCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
}

View File

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

View File

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

View File

@@ -0,0 +1,11 @@
namespace CMSMicroservice.Application.UserRoleCQ.Commands.UpdateUserRole;
public record UpdateUserRoleCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
//شناسه نقش
public long RoleId { get; init; }
//شناسه کاربر
public long UserId { get; init; }
}

View File

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

View File

@@ -0,0 +1,20 @@
namespace CMSMicroservice.Application.UserRoleCQ.Commands.UpdateUserRole;
public class UpdateUserRoleCommandValidator : AbstractValidator<UpdateUserRoleCommand>
{
public UpdateUserRoleCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.RoleId)
.NotNull();
RuleFor(model => model.UserId)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateUserRoleCommand>.CreateWithOptions((UpdateUserRoleCommand)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 @@
using CMSMicroservice.Domain.Events;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.Application.UserRoleCQ.EventHandlers;
public class CreateNewUserRoleEventHandler : INotificationHandler<CreateNewUserRoleEvent>
{
private readonly ILogger<CreateNewUserRoleEventHandler> _logger;
public CreateNewUserRoleEventHandler(ILogger<CreateNewUserRoleEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewUserRoleEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

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

View File

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

View File

@@ -0,0 +1,19 @@
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetAllUserRoleByFilter;
public record GetAllUserRoleByFilterQuery : IRequest<GetAllUserRoleByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllUserRoleByFilterFilter? Filter { get; init; }
}public class GetAllUserRoleByFilterFilter
{
//شناسه
public long? Id { get; set; }
//شناسه نقش
public long? RoleId { get; set; }
//شناسه کاربر
public long? UserId { get; set; }
}

View File

@@ -0,0 +1,32 @@
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetAllUserRoleByFilter;
public class GetAllUserRoleByFilterQueryHandler : IRequestHandler<GetAllUserRoleByFilterQuery, GetAllUserRoleByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllUserRoleByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllUserRoleByFilterResponseDto> Handle(GetAllUserRoleByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.UserRoles
.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.RoleId == null || x.RoleId == request.Filter.RoleId)
.Where(x => request.Filter.UserId == null || x.UserId == request.Filter.UserId)
;
}
return new GetAllUserRoleByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllUserRoleByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}

View File

@@ -0,0 +1,14 @@
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetAllUserRoleByFilter;
public class GetAllUserRoleByFilterQueryValidator : AbstractValidator<GetAllUserRoleByFilterQuery>
{
public GetAllUserRoleByFilterQueryValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllUserRoleByFilterQuery>.CreateWithOptions((GetAllUserRoleByFilterQuery)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}

View File

@@ -0,0 +1,17 @@
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetAllUserRoleByFilter;
public class GetAllUserRoleByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllUserRoleByFilterResponseModel>? Models { get; set; }
}public class GetAllUserRoleByFilterResponseModel
{
//شناسه
public long Id { get; set; }
//شناسه نقش
public long RoleId { get; set; }
//شناسه کاربر
public long UserId { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetUserRole;
public record GetUserRoleQuery : IRequest<GetUserRoleResponseDto>
{
//شناسه
public long Id { get; init; }
}

View File

@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetUserRole;
public class GetUserRoleQueryHandler : IRequestHandler<GetUserRoleQuery, GetUserRoleResponseDto>
{
private readonly IApplicationDbContext _context;
public GetUserRoleQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetUserRoleResponseDto> Handle(GetUserRoleQuery request,
CancellationToken cancellationToken)
{
var response = await _context.UserRoles
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetUserRoleResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(UserRole), request.Id);
}
}

View File

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

View File

@@ -0,0 +1,11 @@
namespace CMSMicroservice.Application.UserRoleCQ.Queries.GetUserRole;
public class GetUserRoleResponseDto
{
//شناسه
public long Id { get; set; }
//شناسه نقش
public long RoleId { get; set; }
//شناسه کاربر
public long UserId { get; set; }
}