Ejemplo n.º 1
0
        public Task <bool> Handle(UpdatePractitionerEmailCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            var existingPractitioner = _practitionerRepository.GetById(message.Id);

            if (existingPractitioner == null)
            {
                _bus.RaiseEvent(new DomainNotification(message.MessageType, "Practitioner not found."));
                return(Task.FromResult(false));
            }

            var practitioner = new Practitioner.Builder(existingPractitioner.Id).Named(existingPractitioner.FullName)
                               .WithCrm(existingPractitioner.CRM)
                               .WithExpertiseIn(existingPractitioner.Expertise).WithPhone(existingPractitioner.Phone)
                               .WithEmail(message.Email).WhichIsActive().Build();

            if (!practitioner.IsValid())
            {
                NotifyValidationErrors(practitioner.ValidationResult);
                return(Task.FromResult(false));
            }

            _practitionerRepository.Update(practitioner);

            if (Commit())
            {
                _bus.RaiseEvent(new PractitionerEmailUpdatedEvent(practitioner));
            }
            return(Task.FromResult(true));
        }
Ejemplo n.º 2
0
        public Task <bool> Handle(RegisterNewPractitionerCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            var practitioner = new Practitioner.Builder(Guid.NewGuid()).Named(message.FullName).WithCrm(message.CRM)
                               .WithExpertiseIn(message.Expertise).WithPhone(message.Phone).WithEmail(message.Email).WhichIsActive()
                               .Build();

            if (_practitionerRepository.GetByCrm(practitioner.CRM) != null)
            {
                _bus.RaiseEvent(new DomainNotification(message.MessageType,
                                                       $"There is already a practitioner registered with this CRM ({practitioner.CRM})"));
                return(Task.FromResult(false));
            }

            _practitionerRepository.Add(practitioner);

            if (Commit())
            {
                _bus.RaiseEvent(new PractitionerRegisteredEvent(practitioner));
            }

            return(Task.FromResult(true));
        }