public async Task <Guid> Handle(Command request, CancellationToken cancellationToken)
            {
                var existingHospital = await _appDbRepository.GetHospitalByIdAsync(request.Id);

                if (existingHospital == null)
                {
                    throw new NotFoundException(nameof(Hospital), request.Id);
                }

                var hospital = new Domain.Entities.Hospital
                {
                    HospitalId   = request.Id,
                    Name         = request.Name,
                    MobileNumber = request.MobileNumber,
                    Address      = new Domain.Entities.Address
                    {
                        Street  = request.Address.Street,
                        City    = request.Address.City,
                        State   = request.Address.State,
                        ZipCode = request.Address.ZipCode
                    }
                };
                await _appDbRepository.EditHospitalByIdAsync(request.Id, hospital);

                return(request.Id);
            }
            public async Task <Hospital> Handle(Query request, CancellationToken cancellationToken)
            {
                var hospital = await _appDbRepository.GetHospitalByIdAsync(request.Id);

                if (hospital == null)
                {
                    throw new NotFoundException(nameof(Hospital), request.Id);
                }
                return(ToHospitalViewModel(hospital));
            }
示例#3
0
            public async Task <Guid> Handle(Command request, CancellationToken cancellationToken)
            {
                var existingPatient = await _appDbRepository.GetPatientByIdAsync(request.Id);

                if (existingPatient == null)
                {
                    throw new NotFoundException(nameof(Patient), request.Id);
                }

                var patientHospitalId = request.HospitalId;

                if (request.HospitalId != null)
                {
                    var hospital = await _appDbRepository.GetHospitalByIdAsync(request.HospitalId.Value);

                    if (hospital == null)
                    {
                        throw new NotFoundException(nameof(Patient), request.HospitalId);
                    }
                    patientHospitalId = hospital.HospitalId;
                }

                var patient = new Domain.Entities.Patient
                {
                    PatientId    = request.Id,
                    Name         = request.Name,
                    DateOfBirth  = request.DateOfBirth,
                    Gender       = (GenderType)request.Gender,
                    MobileNumber = request.MobileNumber,
                    HospitalId   = patientHospitalId,
                    Address      = new Domain.Entities.Address
                    {
                        Street  = request.Address.Street,
                        City    = request.Address.City,
                        State   = request.Address.State,
                        ZipCode = request.Address.ZipCode
                    }
                };
                await _appDbRepository.EditPatientByIdAsync(request.Id, patient);

                _notificationService.Send(new Message
                {
                    Text    = $"Patient updated with the id {request.Id}",
                    Payload = patient
                });
                return(request.Id);
            }