74 lines
2.1 KiB
C#
74 lines
2.1 KiB
C#
|
|
using Books.Api.Domain.Products;
|
||
|
|
using EventFlow.Commands;
|
||
|
|
|
||
|
|
namespace Books.Api.Commands.Products;
|
||
|
|
|
||
|
|
public class CreateProductCommandHandler : CommandHandler<ProductAggregate, ProductId, CreateProductCommand>
|
||
|
|
{
|
||
|
|
public override Task ExecuteAsync(
|
||
|
|
ProductAggregate aggregate,
|
||
|
|
CreateProductCommand command,
|
||
|
|
CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
aggregate.Create(
|
||
|
|
command.CompanyId,
|
||
|
|
command.ProductNumber,
|
||
|
|
command.Name,
|
||
|
|
command.Description,
|
||
|
|
command.UnitPrice,
|
||
|
|
command.VatCode,
|
||
|
|
command.Unit,
|
||
|
|
command.DefaultAccountId,
|
||
|
|
command.Ean,
|
||
|
|
command.Manufacturer);
|
||
|
|
|
||
|
|
return Task.CompletedTask;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public class UpdateProductCommandHandler : CommandHandler<ProductAggregate, ProductId, UpdateProductCommand>
|
||
|
|
{
|
||
|
|
public override Task ExecuteAsync(
|
||
|
|
ProductAggregate aggregate,
|
||
|
|
UpdateProductCommand command,
|
||
|
|
CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
aggregate.Update(
|
||
|
|
command.ProductNumber,
|
||
|
|
command.Name,
|
||
|
|
command.Description,
|
||
|
|
command.UnitPrice,
|
||
|
|
command.VatCode,
|
||
|
|
command.Unit,
|
||
|
|
command.DefaultAccountId,
|
||
|
|
command.Ean,
|
||
|
|
command.Manufacturer);
|
||
|
|
|
||
|
|
return Task.CompletedTask;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public class DeactivateProductCommandHandler : CommandHandler<ProductAggregate, ProductId, DeactivateProductCommand>
|
||
|
|
{
|
||
|
|
public override Task ExecuteAsync(
|
||
|
|
ProductAggregate aggregate,
|
||
|
|
DeactivateProductCommand command,
|
||
|
|
CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
aggregate.Deactivate();
|
||
|
|
return Task.CompletedTask;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public class ReactivateProductCommandHandler : CommandHandler<ProductAggregate, ProductId, ReactivateProductCommand>
|
||
|
|
{
|
||
|
|
public override Task ExecuteAsync(
|
||
|
|
ProductAggregate aggregate,
|
||
|
|
ReactivateProductCommand command,
|
||
|
|
CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
aggregate.Reactivate();
|
||
|
|
return Task.CompletedTask;
|
||
|
|
}
|
||
|
|
}
|