public IActionResult Create(AppointmentParameters aptParams) { //Create a new appointment Appointment apt = new Appointment(); apt.ClientFullName = aptParams.ClientFullName; apt.Date = aptParams.Date; apt.Center = _context.Centers.Find(aptParams.CenterID); // Check to ensure the appointment is valid List <ValidationError> errors = ValidateAppointment(apt); // If there are no errors, then the appointment is created and saved. if (errors.Count == 0) { _context.Appointments.Add(apt); _context.SaveChanges(); return(CreatedAtRoute("GetAppointment", new { id = apt.Id }, apt)); } else { // Otherwise, return a 400 error with a list of errors. return(BadRequest(errors)); } }
public IHttpActionResult GetDoctorAppointmentByDate([FromBody] AppointmentParameters parameters) { if (parameters.DoctorID > 0 && parameters.AppDate != null) { var oDoctorAppointmentDTO = _appointmentService.GetDoctorAppointmentByDate(parameters.DoctorID, parameters.AppDate); return(Ok(oDoctorAppointmentDTO)); } return(BadRequest()); }
public IActionResult Update(int id, AppointmentParameters aptParams) { // Required code to assure relationships between appointments and centers are preserved. // Without this line, centers will be listed as null. var centers = _context.Centers.ToList(); Appointment modItem = _context.Appointments.Find(id); // Item does not exist if null if (modItem == null) { return(NotFound()); } // Set updated fields modItem.ClientFullName = aptParams.ClientFullName; modItem.Date = aptParams.Date; modItem.Center = _context.Centers.Find(aptParams.CenterID); // Validate record is valid List <ValidationError> errors = ValidateAppointment(modItem); // If Valid, update the record and save. Return 204. if (errors.Count == 0) { _context.Appointments.Update(modItem); _context.SaveChanges(); return(NoContent()); } else { // Else, return 400 Bad Request and error list. return(BadRequest(errors)); } }