public IHttpActionResult PutAppointments(int id, AppointmentCustom appointment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != appointment.idAppointment) { return(BadRequest()); } // Validate if the patient already has appointments assigned for today //Appointments patient = db.Appointments.Where(p => p.fk_idPatient == appointment.idPatient //&& p.AppointmentDateTime.Year == appointment.AppointmentDateTime.Year //&& p.AppointmentDateTime.Month == appointment.AppointmentDateTime.Month //&& p.AppointmentDateTime.Day == appointment.AppointmentDateTime.Day).FirstOrDefault(); //if (patient != null) // return NotFound(); int typeId = db.AppointmentsTypes.Where(at => at.name.ToLower() == appointment.appointmentType.ToLower()).FirstOrDefault().idAppointmentType; int doctorId = db.Doctors.Where(at => at.doctorName.ToLower() == appointment.doctorName.ToLower()).FirstOrDefault().idDoctor; Appointments app = new Appointments { idAppointment = appointment.idAppointment, fk_idPatient = appointment.idPatient, fk_idDoctor = doctorId, fk_idAppointmentType = typeId, AppointmentDateTime = appointment.AppointmentDateTime, isActive = true }; db.Entry(app).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AppointmentsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public List <AppointmentCustom> GetCustomAppointments() { List <Appointments> appointments = db.Appointments.ToList(); List <AppointmentCustom> _appointments = new List <AppointmentCustom>(); foreach (Appointments app in appointments) { AppointmentCustom _app = new AppointmentCustom { idAppointment = app.idAppointment, idPatient = app.fk_idPatient, patientName = patientsController.GetPatientName(app.fk_idPatient), appointmentType = GetAppointmentTypeName(app.fk_idAppointmentType), doctorName = GetDoctorName(app.fk_idDoctor), AppointmentDateTime = app.AppointmentDateTime }; _appointments.Add(_app); } return(_appointments); }
public IHttpActionResult CreateAppointment(AppointmentCustom appointment) { //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} // Validate if the patient already has appointments assigned for today Appointments patient = db.Appointments.Where(p => p.fk_idPatient == appointment.idPatient && p.AppointmentDateTime.Year == appointment.AppointmentDateTime.Year && p.AppointmentDateTime.Month == appointment.AppointmentDateTime.Month && p.AppointmentDateTime.Day == appointment.AppointmentDateTime.Day).FirstOrDefault(); if (patient != null) { return(NotFound()); } // Get type and doctors ID int typeId = db.AppointmentsTypes.Where(at => at.name.ToLower() == appointment.appointmentType.ToLower()).FirstOrDefault().idAppointmentType; int doctorId = db.Doctors.Where(at => at.doctorName.ToLower() == appointment.doctorName.ToLower()).FirstOrDefault().idDoctor; Appointments _appointment = new Appointments { fk_idPatient = appointment.idPatient, fk_idDoctor = doctorId, fk_idAppointmentType = typeId, AppointmentDateTime = appointment.AppointmentDateTime, isActive = true }; db.Appointments.Add(_appointment); db.SaveChanges(); //return CreatedAtRoute("DefaultApi", new { id = _appointment.idAppointment }, _appointment); return(Ok()); }