示例#1
0
        public async Task <bool> Handle(RemoveExistingMedicalRecordtByIdCommand message,
                                        CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(await Task.FromResult(false));
            }

            var medicalReport = _medicalRecordRepository.GetByRemovalParamaters(message.MedicalReportId,
                                                                                message.PatientId, message.PractitionerId);

            if (medicalReport == null)
            {
                await _bus.RaiseEvent(new DomainNotification(message.MessageType,
                                                             "No report return from the query, please verify."));

                return(await Task.FromResult(false));
            }


            _medicalRecordRepository.Remove(medicalReport.Id);

            if (await Commit())
            {
                await _bus.RaiseEvent(new MedicalReportRemovedEvent(message.MedicalReportId, message.PatientId,
                                                                    message.PractitionerId));
            }

            return(await Task.FromResult(true));
        }