public async Task Handle(IncomingInvoiceLinkedToJobOrderEvent message) { using (var ctx = new AccountancyDbContext(Options)) { var invoice = ctx.IncomingInvoices.Where(i => i.OriginalId == message.InvoiceId).Single(); invoice.JobOrderId = message.JobOrderId; await ctx.SaveChangesAsync(); } }
/// <summary> /// Associate an incoming invoice to the current Job Order /// </summary> /// <param name="eventStore">The event store</param> /// <param name="invoiceId">The Id of the Invoice to be associated to the current Job Order</param> /// <param name="userId">The Id of the current user</param> /// <exception cref="InvalidOperationException">Thrown if the specified invoiceId refers to an invoice which has already been associated to a Job Order</exception> public void LinkIncomingInvoice(IEventStore eventStore, Guid invoiceId, DateTime dateOfLink, decimal amount, Guid userId) { if (this.IsCompleted) { throw new InvalidOperationException("Can't relate new costs to a completed job order"); } var @event = new IncomingInvoiceLinkedToJobOrderEvent(invoiceId, this.Id, dateOfLink, amount, userId); RaiseEvent(@event); }
public void ApplyEvent(IncomingInvoiceLinkedToJobOrderEvent evt) { this.Balance -= evt.Amount; }