public async Task Handle(OutgoingInvoiceLinkedToJobOrderEvent message)
 {
     using (var ctx = new AccountancyDbContext(Options))
     {
         var invoice = ctx.OutgoingInvoices.Where(i => i.OriginalId == message.InvoiceId).Single();
         invoice.JobOrderId = message.JobOrderId;
         await ctx.SaveChangesAsync();
     }
 }
 public void Handle(OutgoingInvoiceLinkedToJobOrderEvent message)
 {
     using (var ctx = new AccountancyContext())
     {
         var invoice = ctx.OutgoingInvoices.Where(i => i.OriginalId == message.InvoiceId).Single();
         invoice.JobOrderId = message.JobOrderId;
         ctx.SaveChanges();
     }
 }
Beispiel #3
0
        /// <summary>
        /// Associate an outgoing 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 LinkOutgoingInvoice(IEventStore eventStore, Guid invoiceId, DateTime dateOfLink, decimal amount, Guid userId)
        {
            if (this.IsCompleted)
            {
                throw new InvalidOperationException("Can't relate new revenues to a completed job order");
            }
            var @event = new OutgoingInvoiceLinkedToJobOrderEvent(invoiceId, this.Id, dateOfLink, amount, userId);

            RaiseEvent(@event);
        }
Beispiel #4
0
        /// <summary>
        /// Associate an outgoing 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>
        /// <exception cref="InvalidOperationException">Thrown if the specified invoiceId refers to an invoice which has already been associated to a Job Order</exception>
        public void LinkOutgoingInvoice(IEventStore eventStore, Guid invoiceId, DateTime dateOfLink, decimal amount)
        {
            if (this.IsCompleted)
            {
                throw new InvalidOperationException("Can't relate new revenues to a completed job order");
            }
            var count = eventStore.Find <OutgoingInvoiceLinkedToJobOrderEvent>(e => e.InvoiceId == invoiceId && e.JobOrderId == this.Id).Count();

            if (count > 0)
            {
                throw new InvalidOperationException("The specified invoice is already associated to a Job Order.");
            }
            var @event = new OutgoingInvoiceLinkedToJobOrderEvent(invoiceId, this.Id, dateOfLink, amount);

            RaiseEvent(@event);
        }
Beispiel #5
0
 public void ApplyEvent(OutgoingInvoiceLinkedToJobOrderEvent evt)
 {
     this.Balance += evt.Amount;
 }
Beispiel #6
0
 public void ApplyEvent([AggregateId(nameof(OutgoingInvoiceLinkedToJobOrderEvent.JobOrderId))] OutgoingInvoiceLinkedToJobOrderEvent evt)
 {
     this.Balance += evt.Amount;
 }