Esempio n. 1
0
        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 OnVehicleTotaled(OccurrenceSubmittedEvent integrationEvt)
        {
            _logger.LogDebug(integrationEvt.ToIndentedJson());

            var alert = new OccurrenceAlert
            {
                OccurrenceId     = integrationEvt.OccurrenceId,
                FirstName        = integrationEvt.FirstName,
                LastName         = integrationEvt.LastName,
                InsuredState     = integrationEvt.InsuredState,
                PolicyNumber     = integrationEvt.PolicyNumber,
                DateOfOccurrence = integrationEvt.DateOfOccurrence
            };

            await _submissionRepo.AddOccurrenceAlert(alert);
        }