public async Task Handle(JobOrderExtendedEvent message) { using (var db = new AccountancyContext()) { var jobOrder = db.JobOrders.OfType <JobOrder>().Where(jo => jo.OriginalId == message.JobOrderId).Single(); jobOrder.DueDate = message.NewDueDate; jobOrder.Price = message.Price; await db.SaveChangesAsync(); } }
public void Extend(DateTime newDueDate, decimal price) { if (this.IsCompleted) { throw new InvalidOperationException("Can't extend a completed job order."); } if (this.DueDate > newDueDate) { throw new ArgumentException("A job order length cannot be reduced.", nameof(newDueDate)); } var @event = new JobOrderExtendedEvent( this.Id, newDueDate, price ); RaiseEvent(@event); }
public void ApplyEvent(JobOrderExtendedEvent evt) { this.DueDate = evt.NewDueDate; this.Price = new PositiveMoney(evt.Price, this.Price.Currency); }
public void ApplyEvent([AggregateId(nameof(JobOrderExtendedEvent.JobOrderId))] JobOrderExtendedEvent evt) { this.DueDate = evt.NewDueDate; this.Price = new PositiveMoney(evt.Price, this.Price.Currency); }