public async Task <IActionResult> PutAsync(int id, [FromBody] Transfer_Appointment appointment) { _logger.LogInformation($"Editing appointment with id {id}."); var entity = await _appointmentRepository.GetAppointmentByIdAsync(id); if (entity is Inner_Appointment) { entity.AppointmentDate = (DateTime)appointment.AppointmentDate; return(NoContent()); } _logger.LogInformation($"No appointments found with id {id}."); return(NotFound()); }
//This is checking to see if the id's exist public void CheckAppointment(Transfer_Appointment appointment) { //We add the ".Result" because we want the final result of the async methods, we odont want the tasks. //checking to see if the Patient exists in the database if (!(_patientRepo.PatientExistAsync(appointment.PatientId).Result)) { throw new Exception("The Patient does not exist"); } //Checking to see if the user exists in the database if (!(_providerRepo.ProviderExistAsync(appointment.ProviderId).Result)) { throw new HealthPairAppException("The Provider does not exist"); } }
public async Task <IActionResult> PostAsync(Transfer_Appointment appointment) { try { _logger.LogInformation($"Adding new appointment."); var myChecker = new CheckerClass(_patientRepository, _providerRepository, _appointmentRepository); myChecker.CheckAppointment(appointment); Inner_Appointment transformedAppointment = new Inner_Appointment { AppointmentId = 0, AppointmentDate = (DateTime)appointment.AppointmentDate, Patient = await _patientRepository.GetPatientByIdAsync(appointment.PatientId), Provider = await _providerRepository.GetProviderByIdAsync(appointment.ProviderId) }; await _appointmentRepository.AddAppointmentAsync(transformedAppointment); return(CreatedAtAction(nameof(GetByIdAsync), new { id = appointment.AppointmentId }, appointment)); } catch (Exception e) { return(BadRequest(e.Message)); } }