public HttpResponseMessage PostNewAvailableAppointment([FromBody] Available_Appointment newAvailableAppointment) { try { using (Medical_Assistant_System_Entities entities = new Medical_Assistant_System_Entities()) { entities.Available_Appointment.Add(newAvailableAppointment); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, newAvailableAppointment); message.Headers.Location = new Uri(Request.RequestUri + newAvailableAppointment.Id_Available_Appointment.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage PutAvailableAppointment(int apointement_id, Available_Appointment availableAppointment) { try { using (Medical_Assistant_System_Entities entities = new Medical_Assistant_System_Entities()){ var entity = entities.Available_Appointment.FirstOrDefault(ap => ap.Id_Available_Appointment == apointement_id); if (entity != null) { entity.Available_Time = availableAppointment.Available_Time; entity.Prescriptions = availableAppointment.Prescriptions; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "apointement with id =" + apointement_id.ToString() + " not found to update")); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }