public void ApplyVoucher(Voucher voucher) { if (voucher == null) throw new InvalidVoucherInstanceException(); Apply(new VoucherAppliedToCart(CustomerId, voucher.Id, voucher.Amount)); }
public static Voucher CreateVoucher(Guid customerId, Money amount, IVoucherCodeGenerator codeGenerator) { // Validate domain invariants if (customerId == Guid.Empty) throw new ArgumentNullException("customerId"); var voucher = new Voucher(); voucher.Apply(new VoucherCreated(Guid.NewGuid(), customerId, VoucherStatus.Created, amount, codeGenerator.GenerateCode(), DateTime.UtcNow.AddDays(14))); return voucher; }