public async Task Handle(OutgoingCreditNoteLinkedToJobOrderEvent message) { using (var ctx = new AccountancyDbContext(Options)) { var creditNote = ctx.OutgoingCreditNotes.Where(i => i.OriginalId == message.CreditNoteId).Single(); creditNote.JobOrderId = message.JobOrderId; await ctx.SaveChangesAsync(); } }
/// <summary> /// Associate an outgoing credit note to the current Job Order /// </summary> /// <param name="eventStore">The event store</param> /// <param name="creditNoteId">The Id of the Credit note 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 creditNoteId refers to a credit note which has already been associated to a Job Order</exception> public void LinkOutgoingCreditNote(IEventStore eventStore, Guid creditNoteId, 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 OutgoingCreditNoteLinkedToJobOrderEvent(creditNoteId, this.Id, dateOfLink, amount, userId); RaiseEvent(@event); }
public void ApplyEvent(OutgoingCreditNoteLinkedToJobOrderEvent evt) { this.Balance += evt.Amount; }