Generator Changes at 11/16/2025 12:48:45 AM +03:30

This commit is contained in:
masoodafar-web
2025-11-16 00:53:15 +03:30
parent 974f3c788f
commit 0a649325f8
75 changed files with 1460 additions and 7 deletions

View File

@@ -0,0 +1,13 @@
namespace CMSMicroservice.Application.UserContractCQ.Commands.CreateNewUserContract;
public record CreateNewUserContractCommand : IRequest<CreateNewUserContractResponseDto>
{
//شناسه کاربر
public long UserId { get; init; }
//شناسه قرارداد
public long ContractId { get; init; }
//شناسه یکتای امضا
public string SignGuid { get; init; }
//فایل قرارداد
public string SignedPdfFile { get; init; }
}

View File

@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.UserContractCQ.Commands.CreateNewUserContract;
public class CreateNewUserContractCommandHandler : IRequestHandler<CreateNewUserContractCommand, CreateNewUserContractResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewUserContractCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewUserContractResponseDto> Handle(CreateNewUserContractCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<UserContract>();
await _context.UserContracts.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewUserContractEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewUserContractResponseDto>();
}
}

View File

@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.UserContractCQ.Commands.CreateNewUserContract;
public class CreateNewUserContractCommandValidator : AbstractValidator<CreateNewUserContractCommand>
{
public CreateNewUserContractCommandValidator()
{
RuleFor(model => model.UserId)
.NotNull();
RuleFor(model => model.ContractId)
.NotNull();
RuleFor(model => model.SignGuid)
.NotEmpty();
RuleFor(model => model.SignedPdfFile)
.NotEmpty();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewUserContractCommand>.CreateWithOptions((CreateNewUserContractCommand)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.UserContractCQ.Commands.CreateNewUserContract;
public class CreateNewUserContractResponseDto
{
//شناسه
public long Id { get; set; }
}

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,15 @@
namespace CMSMicroservice.Application.UserContractCQ.Commands.UpdateUserContract;
public record UpdateUserContractCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
//شناسه کاربر
public long UserId { get; init; }
//شناسه قرارداد
public long ContractId { get; init; }
//شناسه یکتای امضا
public string SignGuid { get; init; }
//فایل قرارداد
public string SignedPdfFile { get; init; }
}

View File

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

View File

@@ -0,0 +1,24 @@
namespace CMSMicroservice.Application.UserContractCQ.Commands.UpdateUserContract;
public class UpdateUserContractCommandValidator : AbstractValidator<UpdateUserContractCommand>
{
public UpdateUserContractCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.UserId)
.NotNull();
RuleFor(model => model.ContractId)
.NotNull();
RuleFor(model => model.SignGuid)
.NotEmpty();
RuleFor(model => model.SignedPdfFile)
.NotEmpty();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateUserContractCommand>.CreateWithOptions((UpdateUserContractCommand)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.UserContractCQ.EventHandlers;
public class CreateNewUserContractEventHandler : INotificationHandler<CreateNewUserContractEvent>
{
private readonly ILogger<
CreateNewUserContractEventHandler> _logger;
public CreateNewUserContractEventHandler(ILogger<CreateNewUserContractEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewUserContractEvent 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.UserContractCQ.EventHandlers;
public class DeleteUserContractEventHandler : INotificationHandler<DeleteUserContractEvent>
{
private readonly ILogger<
DeleteUserContractEventHandler> _logger;
public DeleteUserContractEventHandler(ILogger<DeleteUserContractEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeleteUserContractEvent 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.UserContractCQ.EventHandlers;
public class UpdateUserContractEventHandler : INotificationHandler<UpdateUserContractEvent>
{
private readonly ILogger<
UpdateUserContractEventHandler> _logger;
public UpdateUserContractEventHandler(ILogger<UpdateUserContractEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdateUserContractEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,23 @@
namespace CMSMicroservice.Application.UserContractCQ.Queries.GetAllUserContractByFilter;
public record GetAllUserContractByFilterQuery : IRequest<GetAllUserContractByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllUserContractByFilterFilter? Filter { get; init; }
}public class GetAllUserContractByFilterFilter
{
//شناسه
public long? Id { get; set; }
//شناسه کاربر
public long? UserId { get; set; }
//شناسه قرارداد
public long? ContractId { get; set; }
//شناسه یکتای امضا
public string? SignGuid { get; set; }
//فایل قرارداد
public string? SignedPdfFile { get; set; }
}

View File

@@ -0,0 +1,34 @@
namespace CMSMicroservice.Application.UserContractCQ.Queries.GetAllUserContractByFilter;
public class GetAllUserContractByFilterQueryHandler : IRequestHandler<GetAllUserContractByFilterQuery, GetAllUserContractByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllUserContractByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllUserContractByFilterResponseDto> Handle(GetAllUserContractByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.UserContracts
.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.UserId == null || x.UserId == request.Filter.UserId)
.Where(x => request.Filter.ContractId == null || x.ContractId == request.Filter.ContractId)
.Where(x => request.Filter.SignGuid == null || x.SignGuid.Contains(request.Filter.SignGuid))
.Where(x => request.Filter.SignedPdfFile == null || x.SignedPdfFile.Contains(request.Filter.SignedPdfFile))
;
}
return new GetAllUserContractByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllUserContractByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}

View File

@@ -0,0 +1,14 @@
namespace CMSMicroservice.Application.UserContractCQ.Queries.GetAllUserContractByFilter;
public class GetAllUserContractByFilterQueryValidator : AbstractValidator<GetAllUserContractByFilterQuery>
{
public GetAllUserContractByFilterQueryValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllUserContractByFilterQuery>.CreateWithOptions((GetAllUserContractByFilterQuery)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.UserContractCQ.Queries.GetAllUserContractByFilter;
public class GetAllUserContractByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllUserContractByFilterResponseModel>? Models { get; set; }
}public class GetAllUserContractByFilterResponseModel
{
//شناسه
public long Id { get; set; }
//شناسه کاربر
public long UserId { get; set; }
//شناسه قرارداد
public long ContractId { get; set; }
//شناسه یکتای امضا
public string SignGuid { get; set; }
//فایل قرارداد
public string SignedPdfFile { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.UserContractCQ.Queries.GetUserContract;
public record GetUserContractQuery : IRequest<GetUserContractResponseDto>
{
//شناسه
public long Id { get; init; }
}

View File

@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.UserContractCQ.Queries.GetUserContract;
public class GetUserContractQueryHandler : IRequestHandler<GetUserContractQuery, GetUserContractResponseDto>
{
private readonly IApplicationDbContext _context;
public GetUserContractQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetUserContractResponseDto> Handle(GetUserContractQuery request,
CancellationToken cancellationToken)
{
var response = await _context.UserContracts
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetUserContractResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(UserContract), request.Id);
}
}

View File

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

View File

@@ -0,0 +1,15 @@
namespace CMSMicroservice.Application.UserContractCQ.Queries.GetUserContract;
public class GetUserContractResponseDto
{
//شناسه
public long Id { get; set; }
//شناسه کاربر
public long UserId { get; set; }
//شناسه قرارداد
public long ContractId { get; set; }
//شناسه یکتای امضا
public string SignGuid { get; set; }
//فایل قرارداد
public string SignedPdfFile { get; set; }
}