public async Task <long?> saveAsync(Cita cita) { try { Medico m = await medRepo.GetMedicoAsync(cita.medicoId); Paciente p = await pacRepo.GetPacienteAsync(cita.pacienteId); cita.medico = m; cita.paciente = p; return(await citaRepo.CreateCitaAsync(cita)); } catch (Exception) { return(null); } }
public async Task <bool> deleteAsync(long id) { try { Paciente pac = await pacRepo.GetPacienteAsync(id); pac.medicos = new HashSet <MedicoPaciente>(); await this.updateAsync(pac); foreach (Cita c in pac.citas) { await diagRepo.DeleteDiagnosticoAsync(c.diagnostico.id); await citaRepo.DeleteCitaAsync(c.id); } pac.citas = new HashSet <Cita>(); await pacRepo.DeletePacienteAsync(id); return(true); } catch (Exception) { return(false); } }
public async Task <bool> updateAsync(Medico med) { try { var updatedMed = await findByIdAsync(med.id); if (updatedMed == null) { return(false); } if (med.usuario != null) { updatedMed.usuario = med.usuario; } if (med.clave != null) { updatedMed.clave = med.clave; } if (med.nombre != null) { updatedMed.nombre = med.nombre; } if (med.apellidos != null) { updatedMed.apellidos = med.apellidos; } if (med.numColegiado != null) { updatedMed.numColegiado = med.numColegiado; } if (med.pacientes != null && !med.pacientes.Equals(updatedMed.pacientes)) { updatedMed.pacientes = med.pacientes; foreach (var mp in updatedMed.pacientes) { mp.medico = updatedMed; mp.paciente = await pacRepo.GetPacienteAsync(mp.pacienteId); } } await medRepo.UpdateMedicoAsync(updatedMed); return(true); } catch (Exception) { return(false); } }