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,11 @@
namespace CMSMicroservice.Application.UserCartsCQ.Commands.CreateNewUserCarts;
public record CreateNewUserCartsCommand : IRequest<CreateNewUserCartsResponseDto>
{
//
public long ProductId { get; init; }
//
public long UserId { get; init; }
//
public int Count { get; init; }
}
@@ -0,0 +1,21 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.UserCartsCQ.Commands.CreateNewUserCarts;
public class CreateNewUserCartsCommandHandler : IRequestHandler<CreateNewUserCartsCommand, CreateNewUserCartsResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateNewUserCartsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateNewUserCartsResponseDto> Handle(CreateNewUserCartsCommand request,
CancellationToken cancellationToken)
{
var entity = request.Adapt<UserCarts>();
await _context.UserCartss.AddAsync(entity, cancellationToken);
entity.AddDomainEvent(new CreateNewUserCartsEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return entity.Adapt<CreateNewUserCartsResponseDto>();
}
}
@@ -0,0 +1,20 @@
namespace CMSMicroservice.Application.UserCartsCQ.Commands.CreateNewUserCarts;
public class CreateNewUserCartsCommandValidator : AbstractValidator<CreateNewUserCartsCommand>
{
public CreateNewUserCartsCommandValidator()
{
RuleFor(model => model.ProductId)
.NotNull();
RuleFor(model => model.UserId)
.NotNull();
RuleFor(model => model.Count)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<CreateNewUserCartsCommand>.CreateWithOptions((CreateNewUserCartsCommand)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.UserCartsCQ.Commands.CreateNewUserCarts;
public class CreateNewUserCartsResponseDto
{
//
public long Id { get; set; }
}
@@ -0,0 +1,7 @@
namespace CMSMicroservice.Application.UserCartsCQ.Commands.DeleteUserCarts;
public record DeleteUserCartsCommand : IRequest<Unit>
{
//
public long Id { get; init; }
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.UserCartsCQ.Commands.DeleteUserCarts;
public class DeleteUserCartsCommandHandler : IRequestHandler<DeleteUserCartsCommand, Unit>
{
private readonly IApplicationDbContext _context;
public DeleteUserCartsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(DeleteUserCartsCommand request, CancellationToken cancellationToken)
{
var entity = await _context.UserCartss
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserCarts), request.Id);
entity.IsDeleted = true;
_context.UserCartss.Update(entity);
entity.AddDomainEvent(new DeleteUserCartsEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,16 @@
namespace CMSMicroservice.Application.UserCartsCQ.Commands.DeleteUserCarts;
public class DeleteUserCartsCommandValidator : AbstractValidator<DeleteUserCartsCommand>
{
public DeleteUserCartsCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<DeleteUserCartsCommand>.CreateWithOptions((DeleteUserCartsCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}
@@ -0,0 +1,13 @@
namespace CMSMicroservice.Application.UserCartsCQ.Commands.UpdateUserCarts;
public record UpdateUserCartsCommand : IRequest<Unit>
{
//
public long Id { get; init; }
//
public long ProductId { get; init; }
//
public long UserId { get; init; }
//
public int Count { get; init; }
}
@@ -0,0 +1,22 @@
using CMSMicroservice.Domain.Events;
namespace CMSMicroservice.Application.UserCartsCQ.Commands.UpdateUserCarts;
public class UpdateUserCartsCommandHandler : IRequestHandler<UpdateUserCartsCommand, Unit>
{
private readonly IApplicationDbContext _context;
public UpdateUserCartsCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<Unit> Handle(UpdateUserCartsCommand request, CancellationToken cancellationToken)
{
var entity = await _context.UserCartss
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserCarts), request.Id);
request.Adapt(entity);
_context.UserCartss.Update(entity);
entity.AddDomainEvent(new UpdateUserCartsEvent(entity));
await _context.SaveChangesAsync(cancellationToken);
return Unit.Value;
}
}
@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.UserCartsCQ.Commands.UpdateUserCarts;
public class UpdateUserCartsCommandValidator : AbstractValidator<UpdateUserCartsCommand>
{
public UpdateUserCartsCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.ProductId)
.NotNull();
RuleFor(model => model.UserId)
.NotNull();
RuleFor(model => model.Count)
.NotNull();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateUserCartsCommand>.CreateWithOptions((UpdateUserCartsCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}