Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
61 lines (52 sloc) 2.03 KB
#if NETSTANDARD // AspNetCoreMvcApp
using CoreDdd.Commands;
using CoreDdd.Domain.Repositories;
using CoreDddShared.Domain;
using System.Threading.Tasks;
namespace CoreDddShared.Commands
{
public class CreateNewShipCommandHandler : BaseCommandHandler<CreateNewShipCommand>
{
private readonly IRepository<Ship> _shipRepository;
public CreateNewShipCommandHandler(IRepository<Ship> shipRepository)
{
_shipRepository = shipRepository;
}
public override async Task ExecuteAsync(CreateNewShipCommand command)
{
var newShip = new Ship(command.ShipName, command.Tonnage, command.ImoNumber);
await _shipRepository.SaveAsync(newShip);
newShip.OnCreationCompleted();
RaiseCommandExecutedEvent(new CommandExecutedArgs { Args = newShip.Id });
}
}
}
#endif
#if NET40 // LegacyWebFormsApp
using CoreDdd.Commands;
using CoreDdd.Domain.Repositories;
using CoreDddShared.Domain;
namespace CoreDddShared.Commands
{
public class CreateNewShipCommandHandler : BaseCommandHandler<CreateNewShipCommand>
{
private readonly IRepository<Ship> _shipRepository;
private readonly IInternationalMaritimeOrganizationVerifier _internationalMaritimeOrganizationVerifier;
public CreateNewShipCommandHandler(
IRepository<Ship> shipRepository,
IInternationalMaritimeOrganizationVerifier internationalMaritimeOrganizationVerifier
)
{
_internationalMaritimeOrganizationVerifier = internationalMaritimeOrganizationVerifier;
_shipRepository = shipRepository;
}
public override void Execute(CreateNewShipCommand command)
{
var newShip = new Ship(command.ShipName, command.Tonnage, command.ImoNumber);
newShip.VerifyImoNumber(_internationalMaritimeOrganizationVerifier);
_shipRepository.Save(newShip);
RaiseCommandExecutedEvent(new CommandExecutedArgs { Args = newShip.Id });
}
}
}
#endif
You can’t perform that action at this time.