示例#1
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] Transfer_Patient patient)
        {
            _logger.LogInformation($"Editing patient with id {id}.");
            var entity = await _patientRepository.GetPatientByIdAsync(id);

            if (entity is Inner_Patient)
            {
                entity.PatientAddress1    = patient.PatientAddress1;
                entity.PatientBirthDay    = patient.PatientBirthDay;
                entity.PatientCity        = patient.PatientCity;
                entity.PatientFirstName   = patient.PatientFirstName;
                entity.PatientLastName    = patient.PatientLastName;
                entity.PatientPassword    = patient.PatientPassword;
                entity.PatientPhoneNumber = patient.PatientPhoneNumber;
                entity.PatientState       = patient.PatientState;
                entity.PatientZipcode     = patient.PatientZipcode;
                entity.Insurance          = await _insuranceRepository.GetInsuranceByIdAsync(patient.InsuranceId);

                await _patientRepository.UpdatePatientAsync(entity);

                return(NoContent());
            }
            _logger.LogInformation($"No patients found with id {id}.");
            return(NotFound());
        }
 public void CheckPatient(Transfer_Patient patient)
 {
     if (!(_insuranceRepo.InsuranceExistAsync(patient.InsuranceId).Result))
     {
         throw new HealthPairAppException("The insurance you chose does not exist, please choose the correct insurance");
     }
 }
示例#3
0
        public async Task <IActionResult> PostAsync(Transfer_Patient patient)
        {
            try
            {
                _logger.LogInformation($"Adding new patient.");
                var checkPatient = new CheckerClass(_patientRepository, _insuranceRepository);
                checkPatient.CheckPatient(patient);
                Inner_Patient transformedPatient = new Inner_Patient
                {
                    PatientId          = 0,
                    PatientFirstName   = patient.PatientFirstName,
                    PatientLastName    = patient.PatientLastName,
                    PatientPassword    = patient.PatientPassword,
                    PatientAddress1    = patient.PatientAddress1,
                    PatientCity        = patient.PatientCity,
                    PatientState       = patient.PatientState,
                    PatientZipcode     = patient.PatientZipcode,
                    PatientBirthDay    = patient.PatientBirthDay,
                    PatientPhoneNumber = patient.PatientPhoneNumber,
                    PatientEmail       = patient.PatientEmail,
                    Insurance          = await _insuranceRepository.GetInsuranceByIdAsync(patient.InsuranceId)
                };
                await _patientRepository.AddPatientAsync(transformedPatient);

                return(CreatedAtAction(nameof(GetByIdAsync), new { id = patient.PatientId }, patient));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }