public IEnumerable <IEvent <ProjectTimeAggregateRoot, int> > Execute(MarkInvoiceAsPaidCommand command) { CheckUserBillingRights(command.ProjectId, command.ByUserId); var userInvoices = State.Invoices.Where(i => i.InvoiceNum == command.InvoiceNum); if (!userInvoices.Any()) { throw new ArgumentException("Invoice number is not valid: invoice either cancelled or not exists."); } var events = userInvoices.Select(ui => new InvoiceEvent { At = DateTimeOffset.Now, EventType = InvoiceEventType.Paid, Hours = ui.Hours, InvoiceNum = ui.InvoiceNum, InvoiceSum = ui.Sum, ProjectId = command.ProjectId, UserId = ui.UserId, RegisteredAt = DateTimeOffset.Now, RegisteredByUserId = command.ByUserId }); return(events); }
public async Task <ActionResult> MarkAsPaid([FromRoute] Guid id, MarkInvoiceAsPaidCommand command, CancellationToken cancellationToken) { command.SetInvoiceId(id); await Mediator.Send(command, cancellationToken); return(NoContent()); }
public void MarkInvoiceAsPaid(int projectId, string invoiceNum) { if (String.IsNullOrWhiteSpace(invoiceNum)) { throw new ArgumentNullException("invoiceNum"); } var command = new MarkInvoiceAsPaidCommand { ByUserId = _currentUser.Id, InvoiceNum = invoiceNum, ProjectId = projectId }; _cqrs.Execute(command); }