// DELETE api/appointments/4 public HttpResponseMessage Delete(int id) { var appointment = new Appointment { AppointmentId = id }; _db.Appointments.Attach(appointment); var status=_db.Appointments.Remove(appointment); _db.SaveChanges(); if (status != null) return new HttpResponseMessage(HttpStatusCode.OK); throw new HttpResponseException(HttpStatusCode.NotFound); }
// POST /api/appointments public HttpResponseMessage Post([FromBody] AppointmentInModel values) { var custId=_db.Customers.FirstOrDefault(c=>c.PhoneNumber==values.CustomerPhoneNumber).CustomerId; var empId=_db.Employees.Where(e=>e.FirstName==values.EmployeeFirstName).Where(e=>e.LastName==values.EmployeeLastName).FirstOrDefault().EmployeeId; var servId=_db.Services.FirstOrDefault(e=>e.ServiceName==values.ServiceName).ServiceId; var appointment = new Appointment { CustomerId=custId, EmployeeId=empId, ServiceId=servId, Start=values.AppointmentStartTime, Duration=values.AppointmentDurationInMins, Paid=values.CustomerPaid, Confirmation=values.AppointmentConfirmation, EmployeeRequested=values.IsEmployeeRequested, Remarks=values.AppointmentRemarks }; var appt = _db.Appointments.Add(appointment); _db.SaveChanges(); if (appt != null) { var msg = new HttpResponseMessage(HttpStatusCode.Created); msg.Headers.Location = new Uri(Request.RequestUri + "/" + appointment.AppointmentId.ToString()); return msg; } else { var msg = new HttpResponseMessage(HttpStatusCode.BadRequest); return msg; } }