public async Task <Confirmation> Record(OccurrenceCommand command) { var insured = Contact.IdentifiedAs(command.FirstName, command.LastName, command.DateOfBirth) .PrimaryContactInfo(command.PhoneNumber) .InsuredBy("Docker Insurance Company Inc.", command.PolicyNumber, command.InsuredState); var occurrence = Occurrence.ForInsured(insured, command.DateOfOccurrence); ValidationResultSet valResultSet = _validation.Validate(occurrence); if (valResultSet.IsInvalid) { return(new Confirmation { Validations = valResultSet.ObjectValidations }); } await _occurenceRepo.AddOccurrenceAsync(occurrence); // Publish domain event on message bus to notify other interested Microservices. var domainEvent = OccurrenceSubmittedEvent.FromOccurrence(occurrence); await _messaging.PublishAsync(domainEvent); return(new Confirmation { OccurrenceId = occurrence.OccurrenceId }); }
public async Task <IActionResult> Report([FromBody] OccurrenceCommand command) { Confirmation confirmation = await _messaging.SendAsync(command); if (confirmation.Validations.Empty()) { return(Ok(confirmation)); } return(BadRequest(confirmation)); }