public void Handle(DebitApplied message) { balance -= message.Amount; Console.WriteLine(); Console.WriteLine($"DebitApplied: ${message.Amount:0.00}"); Console.WriteLine($"Balance: ${balance:0.00}"); }
public IDomainEventCollection Debit(decimal amount, CanDebitAccount canDebitAccount) { Contract.Requires(canDebitAccount != null); Contract.Ensures(Contract.Result <IDomainEventCollection>() != null); string declinationReason; if (canDebitAccount(this, amount, out declinationReason)) { Balance -= amount; var debitApplied = new DebitApplied(Identity, amount, Balance); if (Overdrawn) { return(new DomainEventCollection(this, new Collection <IDomainEvent> { debitApplied, new DebitOverdrawn(Identity, Balance) })); } return(new DomainEventCollection(this, debitApplied)); } return(new DomainEventCollection(this, new DebitDeclined(Identity, amount, Balance, declinationReason))); }
private IEnumerable <SqlNonQueryCommand> DebitAppliedHandler(DebitApplied @event) { var result = new List <SqlNonQueryCommand>(); var lastAccount = @event.Account.Split(":").Last(); var lastAccountPrefix = lastAccount.Split("|").First(); var lastAccountId = lastAccount.Split("|").Last(); if (lastAccountPrefix == "WL") { var command = Sql.NonQueryStatement( @"declare @Amount int = (select top 1 Amount FROM [OnHandInventoryView] where skuId = @SkuId and ReservationId IS NULL and location = @Location) IF(@Amount IS NULL) INSERT INTO [OnHandInventoryView] ([Location],[Amount],[SkuId],[ReservationId]) VALUES (@Location, @AmountToAppend, @SkuId, NULL) ELSE UPDATE [OnHandInventoryView] SET [Amount] = @Amount + @AmountToAppend WHERE SkuId = @SkuId and ReservationId IS NULL" , new { SkuId = Sql.UniqueIdentifier(@event.SkuId), AmountToAppend = Sql.Int(@event.Amount), Location = Sql.VarChar(lastAccountId, 50) }); result.Add(command); } else if (lastAccountPrefix == "R") { var penUltimateAccount = @event.Account.Split(":").Reverse().Skip(1).First(); var penultimateAccountId = penUltimateAccount.Split("|").Last(); var command = Sql.NonQueryStatement( @"declare @Amount int = (select top 1 Amount FROM [OnHandInventoryView] where skuId = @SkuId and ReservationId = @ReservationId and Location = @Location) IF(@Amount IS NULL) INSERT INTO [OnHandInventoryView] ([Location],[Amount],[SkuId],[ReservationId]) VALUES (@Location, @ReservedAmount, @SkuId, @ReservationId) ELSE UPDATE [OnHandInventoryView] SET [Amount] = @Amount + @ReservedAmount WHERE SkuId = @SkuId and ReservationId = @ReservationId" , new { SkuId = Sql.UniqueIdentifier(@event.SkuId), ReservedAmount = Sql.Int(@event.Amount), Location = Sql.VarChar(penultimateAccountId, 50), ReservationId = Sql.UniqueIdentifier(Guid.Parse(lastAccountId)) }); result.Add(command); } return(result); }
private static void DebitApplied(MemoryCache cache, DebitApplied message) { var account = Account.Parse(message.Account); if (!account.ContainsComponent <WarehouseLocationComponent>()) { return; } var accountId = account.GetId(); var location = account.GetComponent <WarehouseLocationComponent>(); var reservation = account.TryGetComponent <ReservationComponent>(); var id = StockLinePartId.NewId(message.SkuId, accountId, message.SkuMetadata); message.SkuMetadata.TryGetValue("Batch", out var batchValue); if (cache.TryGetValue(id, out StockLine stockLine)) { stockLine.Amount += message.Amount; } else { cache.Set(id, new StockLine { SkuId = message.SkuId, Amount = message.Amount, LocationId = location.LocationId, ReservationId = reservation?.ReservationId, Batch = Convert.ToString(batchValue), AccountId = accountId.ToString(), NetWeight = cache.Get <Sku>(message.SkuId).GetNetWeight() * message.Amount, Account = account.ToString(), SkuDescription = cache.Get <Sku>(message.SkuId).Description }); } }
private void Apply(DebitApplied @event) { Balance -= @event.Amount; }
public void Handle(DebitApplied message) { }
private void When(DebitApplied domainEvent) { Balance = domainEvent.NewBalance; }
public void Handle(DebitApplied message) { _balance -= message.Amount; _accountUpdateMessage.Update($"Debit: ${message.Amount:0.00} - Balance: ${_balance:0.00}"); }