public async Task <ActionResult <Hora> > PostHora(Hora hora) { _context.Horas.Add(hora); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetHoraItem), new { id = hora.Horario }, hora)); }
public async Task <ActionResult <Cita> > PostCita(CrearCitaRequest cita) { var doctor = await _context.Doctores.FindAsync(cita.Identificacion_Doctor); var paciente = await _context.Pacientes.FindAsync(cita.Identificacion_Paciente); var horario = await _context.Horas.FindAsync(cita.Horario); if (doctor == null) { ModelState.AddModelError("Doctor", "El valor del crédito debe ser menor a $100.000"); } if (paciente == null) { ModelState.AddModelError("Paciente", "El valor del crédito debe ser menor a $100.000"); } if (horario == null) { ModelState.AddModelError("Horario", "El valor del crédito debe ser menor a $100.000"); } if (!ModelState.IsValid) { var problemDetails = new ValidationProblemDetails(ModelState) { Status = StatusCodes.Status400BadRequest, }; return(BadRequest(problemDetails)); } var citaNueva = new Cita { Doctor = doctor, Paciente = paciente, Hora = horario, Fecha = cita.Fecha }; _context.Citas.Add(citaNueva); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetCitaAdo), new { id = cita.Id }, cita)); }
public async Task <ActionResult <Doctor> > PostDoctor(Doctor doctor) { var doctorItem = await _context.Doctores.FindAsync(doctor.Identificacion_Doctor); if (doctorItem != null) { return(BadRequest()); } else { _context.Doctores.Add(doctor); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetDoctorItem), new { id = doctor.Identificacion_Doctor }, doctor)); } }
public async Task <ActionResult <Paciente> > PostPaciente(Paciente paciente) { var pacienteItem = await _context.Pacientes.FindAsync(paciente.Identificacion_Paciente); if (pacienteItem != null) { return(BadRequest()); } else { _context.Pacientes.Add(paciente); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetPacienteItem), new { id = paciente.Identificacion_Paciente }, paciente)); } }
public async Task <ActionResult <Tratamiento> > PostTratamiento(Tratamiento newTratamiento) { var tratamientoItem = await _context.Tratamientos.FindAsync(newTratamiento.Codigo_Tratamiento); if (tratamientoItem != null) { return(BadRequest()); } else { _context.Tratamientos.Add(newTratamiento); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetTratamientoItem), new { id = newTratamiento.Codigo_Tratamiento }, newTratamiento)); } }