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,17 @@
namespace CMSMicroservice.Application.UserOrderCQ.Commands.CreateNewUserOrder;
public record CreateNewUserOrderCommand : IRequest<CreateNewUserOrderResponseDto>
{
//قیمت
public long Price { get; init; }
//شناسه پکیج
public long PackageId { get; init; }
//شناسه تراکنش
public long? TransactionId { get; init; }
//وضعیت پرداخت
public bool PaymentStatus { get; init; }
//تاریخ پرداخت
public DateTime? PaymentDate { get; init; }
//شناسه کاربر
public long UserId { get; init; }
}

View File

@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.UserOrderCQ.Commands.CreateNewUserOrder;
public class CreateNewUserOrderCommandHandler : IRequestHandler<CreateNewUserOrderCommand, CreateNewUserOrderResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewUserOrderCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewUserOrderResponseDto> Handle(CreateNewUserOrderCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<UserOrder>();
await _context.UserOrders.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewUserOrderEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewUserOrderResponseDto>();
}
}

View File

@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.UserOrderCQ.Commands.CreateNewUserOrder;
public class CreateNewUserOrderCommandValidator : AbstractValidator<CreateNewUserOrderCommand>
{
public CreateNewUserOrderCommandValidator()
{
RuleFor(model => model.Price)
.NotNull();
RuleFor(model => model.PackageId)
.NotNull();
RuleFor(model => model.PaymentStatus)
.NotNull();
RuleFor(model => model.UserId)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewUserOrderCommand>.CreateWithOptions((CreateNewUserOrderCommand)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.UserOrderCQ.Commands.CreateNewUserOrder;
public class CreateNewUserOrderResponseDto
{
//شناسه
public long Id { get; set; }
}

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,19 @@
namespace CMSMicroservice.Application.UserOrderCQ.Commands.UpdateUserOrder;
public record UpdateUserOrderCommand : IRequest<Unit>
{
//شناسه
public long Id { get; init; }
//قیمت
public long Price { get; init; }
//شناسه پکیج
public long PackageId { get; init; }
//شناسه تراکنش
public long? TransactionId { get; init; }
//وضعیت پرداخت
public bool PaymentStatus { get; init; }
//تاریخ پرداخت
public DateTime? PaymentDate { get; init; }
//شناسه کاربر
public long UserId { get; init; }
}

View File

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

View File

@@ -0,0 +1,24 @@
namespace CMSMicroservice.Application.UserOrderCQ.Commands.UpdateUserOrder;
public class UpdateUserOrderCommandValidator : AbstractValidator<UpdateUserOrderCommand>
{
public UpdateUserOrderCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.Price)
.NotNull();
RuleFor(model => model.PackageId)
.NotNull();
RuleFor(model => model.PaymentStatus)
.NotNull();
RuleFor(model => model.UserId)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateUserOrderCommand>.CreateWithOptions((UpdateUserOrderCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}