public async Task <IHttpActionResult> Post(HttpRequestMessage request) { string body = await request.Content.ReadAsStringAsync(); if (!String.IsNullOrEmpty(body)) { JObject json = JObject.Parse(body); using (var medicalAppointment = new MedicalAppointmentContext()) { var appointmentobject = JsonConvert.DeserializeObject <Appointment>(json.ToString()); Appointment appointment = new Appointment(); appointment.AppointmentId = Guid.NewGuid(); appointment.AppointmentDate = appointmentobject.AppointmentDate; appointment.SpecialistId = appointmentobject.SpecialistId; appointment.AppointmentStatus = appointmentobject.AppointmentStatus; appointment.UserId = appointmentobject.UserId; var newAppointment = medicalAppointment.Appointments.Add(appointment); medicalAppointment.SaveChanges(); return(Ok(newAppointment)); } } return(BadRequest()); }
public IHttpActionResult Post([FromBody] User user) { using (var medicalAppointment = new MedicalAppointmentContext()) { var newuser = medicalAppointment.Users.Add(user); medicalAppointment.SaveChanges(); return(Ok(newuser)); } }
public IHttpActionResult Delete(string Id) { using (var medicalAppointment = new MedicalAppointmentContext()) { var userid = Guid.Parse(Id); var user = medicalAppointment.Users.FirstOrDefault(u => u.UserId == userid); medicalAppointment.Users.Remove(user); medicalAppointment.SaveChanges(); return(Ok()); } }
public IHttpActionResult UpdateStatus(Appointment Appointment, string Id) { using (var medicalAppointment = new MedicalAppointmentContext()) { var Appointmentid = Guid.Parse(Id); var oldAppointment = medicalAppointment.Appointments.FirstOrDefault(u => u.AppointmentId == Appointmentid); oldAppointment.AppointmentStatus = Appointment.AppointmentStatus; medicalAppointment.SaveChanges(); return(Ok(Appointment)); } }
public IHttpActionResult Patch([FromBody] User user, string Id) { using (var medicalAppointment = new MedicalAppointmentContext()) { var userid = Guid.Parse(Id); var oldUser = medicalAppointment.Users.FirstOrDefault(u => u.UserId == userid); oldUser.Name = user.Name; oldUser.LastName = user.LastName; oldUser.Nit = user.Nit; oldUser.Email = user.Email; medicalAppointment.SaveChanges(); return(Ok(user)); } }