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

View File

@@ -0,0 +1,13 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Commands.UpdateProductImages;
public record UpdateProductImagesCommand : IRequest<Unit>
{
//
public long Id { get; init; }
//
public string Title { get; init; }
//
public string ImagePath { get; init; }
//
public string ImageThumbnailPath { get; init; }
}

View File

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

View File

@@ -0,0 +1,22 @@
namespace CMSMicroservice.Application.ProductImagesCQ.Commands.UpdateProductImages;
public class UpdateProductImagesCommandValidator : AbstractValidator<UpdateProductImagesCommand>
{
public UpdateProductImagesCommandValidator()
{
RuleFor(model => model.Id)
.NotNull();
RuleFor(model => model.Title)
.NotEmpty();
RuleFor(model => model.ImagePath)
.NotEmpty();
RuleFor(model => model.ImageThumbnailPath)
.NotEmpty();
}
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
{
var result = await ValidateAsync(ValidationContext<UpdateProductImagesCommand>.CreateWithOptions((UpdateProductImagesCommand)model, x => x.IncludeProperties(propertyName)));
if (result.IsValid)
return Array.Empty<string>();
return result.Errors.Select(e => e.ErrorMessage);
};
}