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

@@ -6,8 +6,6 @@ public interface IApplicationDbContext
DbSet<Package> Packages { get; }
DbSet<Role> Roles { get; }
DbSet<UserRole> UserRoles { get; }
DbSet<OtpToken> OtpTokens { get; }
DbSet<User> Users { get; }
DbSet<UserWallet> UserWallets { get; }
DbSet<UserWalletChangeLog> UserWalletChangeLogs { get; }
DbSet<UserCarts> UserCartss { get; }
@@ -17,5 +15,9 @@ public interface IApplicationDbContext
DbSet<Products> Productss { get; }
DbSet<ProductImages> ProductImagess { get; }
DbSet<Transactions> Transactionss { get; }
DbSet<User> Users { get; }
DbSet<OtpToken> OtpTokens { get; }
DbSet<Contract> Contracts { get; }
DbSet<UserContract> UserContracts { get; }
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}

View File

@@ -0,0 +1,10 @@
namespace CMSMicroservice.Application.Common.Mappings;
public class ContractProfile : IRegister
{
void IRegister.Register(TypeAdapterConfig config)
{
//config.NewConfig<Source,Destination>()
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
}
}

View File

@@ -0,0 +1,10 @@
namespace CMSMicroservice.Application.Common.Mappings;
public class UserContractProfile : IRegister
{
void IRegister.Register(TypeAdapterConfig config)
{
//config.NewConfig<Source,Destination>()
// .Map(dest => dest.FullName, src => $"{src.Firstname} {src.Lastname}");
}
}

View File

@@ -0,0 +1,13 @@
namespace CMSMicroservice.Application.ContractCQ.Commands.CreateNewContract;
public record CreateNewContractCommand : IRequest<CreateNewContractResponseDto>
{
//عنوان
public string Title { get; init; }
//توضیحات
public string Description { get; init; }
//متن قرارداد
public string HtmlContent { get; init; }
//نوع قرارداد
public UnknownEnumType Type { get; init; }
}

View File

@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.ContractCQ.Commands.CreateNewContract;
public class CreateNewContractCommandHandler : IRequestHandler<CreateNewContractCommand, CreateNewContractResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewContractCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewContractResponseDto> Handle(CreateNewContractCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<Contract>();
await _context.Contracts.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewContractEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewContractResponseDto>();
}
}

View File

@@ -0,0 +1,23 @@
namespace CMSMicroservice.Application.ContractCQ.Commands.CreateNewContract;
public class CreateNewContractCommandValidator : AbstractValidator<CreateNewContractCommand>
{
public CreateNewContractCommandValidator()
{
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.Description)
.NotEmpty();
RuleFor(model => model.HtmlContent)
.NotEmpty();
RuleFor(model => model.Type)
.IsInEnum()
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewContractCommand>.CreateWithOptions((CreateNewContractCommand)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.ContractCQ.Commands.CreateNewContract;
public class CreateNewContractResponseDto
{
//شناسه
public long Id { get; set; }
}

View File

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

View File

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

View File

@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.ContractCQ.Commands.DeleteContract;
public class DeleteContractCommandValidator : AbstractValidator<DeleteContractCommand>
{
public DeleteContractCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeleteContractCommand>.CreateWithOptions((DeleteContractCommand)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.ContractCQ.Commands.UpdateContract;
public record UpdateContractCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
//عنوان
public string Title { get; init; }
//توضیحات
public string Description { get; init; }
//متن قرارداد
public string HtmlContent { get; init; }
//نوع قرارداد
public UnknownEnumType Type { get; init; }
}

View File

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

View File

@@ -0,0 +1,25 @@
namespace CMSMicroservice.Application.ContractCQ.Commands.UpdateContract;
public class UpdateContractCommandValidator : AbstractValidator<UpdateContractCommand>
{
public UpdateContractCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.Description)
.NotEmpty();
RuleFor(model => model.HtmlContent)
.NotEmpty();
RuleFor(model => model.Type)
.IsInEnum()
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateContractCommand>.CreateWithOptions((UpdateContractCommand)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.ContractCQ.EventHandlers;
public class CreateNewContractEventHandler : INotificationHandler<CreateNewContractEvent>
{
private readonly ILogger<
CreateNewContractEventHandler> _logger;
public CreateNewContractEventHandler(ILogger<CreateNewContractEventHandler> logger)
{
_logger = logger;
}
public Task Handle(CreateNewContractEvent 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.ContractCQ.EventHandlers;
public class DeleteContractEventHandler : INotificationHandler<DeleteContractEvent>
{
private readonly ILogger<
DeleteContractEventHandler> _logger;
public DeleteContractEventHandler(ILogger<DeleteContractEventHandler> logger)
{
_logger = logger;
}
public Task Handle(DeleteContractEvent 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.ContractCQ.EventHandlers;
public class UpdateContractEventHandler : INotificationHandler<UpdateContractEvent>
{
private readonly ILogger<
UpdateContractEventHandler> _logger;
public UpdateContractEventHandler(ILogger<UpdateContractEventHandler> logger)
{
_logger = logger;
}
public Task Handle(UpdateContractEvent notification, CancellationToken cancellationToken)
{
_logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name);
return Task.CompletedTask;
}
}

View File

@@ -0,0 +1,23 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetAllContractByFilter;
public record GetAllContractByFilterQuery : IRequest<GetAllContractByFilterResponseDto>
{
//موقعیت صفحه بندی
public PaginationState? PaginationState { get; init; }
//مرتب سازی بر اساس
public string? SortBy { get; init; }
//فیلتر
public GetAllContractByFilterFilter? Filter { get; init; }
}public class GetAllContractByFilterFilter
{
//شناسه
public long? Id { get; set; }
//عنوان
public string? Title { get; set; }
//توضیحات
public string? Description { get; set; }
//متن قرارداد
public string? HtmlContent { get; set; }
//نوع قرارداد
public UnknownEnumType Type { get; set; }
}

View File

@@ -0,0 +1,34 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetAllContractByFilter;
public class GetAllContractByFilterQueryHandler : IRequestHandler<GetAllContractByFilterQuery, GetAllContractByFilterResponseDto>
{
private readonly IApplicationDbContext _context;
public GetAllContractByFilterQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetAllContractByFilterResponseDto> Handle(GetAllContractByFilterQuery request, CancellationToken cancellationToken)
{
var query = _context.Contracts
.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.Title == null || x.Title.Contains(request.Filter.Title))
.Where(x => request.Filter.Description == null || x.Description.Contains(request.Filter.Description))
.Where(x => request.Filter.HtmlContent == null || x.HtmlContent.Contains(request.Filter.HtmlContent))
.Where(x => request.Filter.Type == null || x.Type == request.Filter.Type)
;
}
return new GetAllContractByFilterResponseDto
{
MetaData = await query.GetMetaData(request.PaginationState, cancellationToken),
Models = await query.PaginatedListAsync(paginationState: request.PaginationState)
.ProjectToType<GetAllContractByFilterResponseModel>().ToListAsync(cancellationToken)
};
}
}

View File

@@ -0,0 +1,14 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetAllContractByFilter;
public class GetAllContractByFilterQueryValidator : AbstractValidator<GetAllContractByFilterQuery>
{
public GetAllContractByFilterQueryValidator()
{
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetAllContractByFilterQuery>.CreateWithOptions((GetAllContractByFilterQuery)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.ContractCQ.Queries.GetAllContractByFilter;
public class GetAllContractByFilterResponseDto
{
//متادیتا
public MetaData MetaData { get; set; }
//مدل خروجی
public List<GetAllContractByFilterResponseModel>? Models { get; set; }
}public class GetAllContractByFilterResponseModel
{
//شناسه
public long Id { get; set; }
//عنوان
public string Title { get; set; }
//توضیحات
public string Description { get; set; }
//متن قرارداد
public string HtmlContent { get; set; }
//نوع قرارداد
public UnknownEnumType Type { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetContract;
public record GetContractQuery : IRequest<GetContractResponseDto>
{
//شناسه
public long Id { get; init; }
}

View File

@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetContract;
public class GetContractQueryHandler : IRequestHandler<GetContractQuery, GetContractResponseDto>
{
private readonly IApplicationDbContext _context;
public GetContractQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetContractResponseDto> Handle(GetContractQuery request,
CancellationToken cancellationToken)
{
var response = await _context.Contracts
.AsNoTracking()
.Where(x => x.Id == request.Id)
.ProjectToType<GetContractResponseDto>()
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(Contract), request.Id);
}
}

View File

@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.ContractCQ.Queries.GetContract;
public class GetContractQueryValidator : AbstractValidator<GetContractQuery>
{
public GetContractQueryValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<GetContractQuery>.CreateWithOptions((GetContractQuery)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.ContractCQ.Queries.GetContract;
public class GetContractResponseDto
{
//شناسه
public long Id { get; set; }
//عنوان
public string Title { get; set; }
//توضیحات
public string Description { get; set; }
//متن قرارداد
public string HtmlContent { get; set; }
//نوع قرارداد
public UnknownEnumType Type { get; set; }
}

View File

@@ -5,7 +5,5 @@ public record CreateNewOtpTokenCommand : IRequest<CreateNewOtpTokenResponseDto>
public string Mobile { get; init; }
//مقصود
public string Purpose { get; init; }
//اطلاعات بیشتر
public string? ExtraInfo { get; init; }
}

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