public IHttpActionResult Persist(PersistAppointmentRequest request)
        {
            setAppointmentDate(request);

            if (request.Appointment.Id == 0)
            {
                db.Appointments.Add(request.Appointment);
            }

            if (request.Appointment.Id > 0)
            {
                var appointmentEntity = db.Appointments.FirstOrDefault(x => x.Id == request.Appointment.Id);
                appointmentEntity.DoctorId         = request.Appointment.DoctorId;
                appointmentEntity.PatientId        = request.Appointment.PatientId;
                appointmentEntity.ConsultationTime = request.Appointment.ConsultationTime;
                if (request.Appointment.PatientId == 0)
                {
                    appointmentEntity.Patient = request.Appointment.Patient;
                }
                if (request.Appointment.CreditCardPayment != null)
                {
                    appointmentEntity.CreditCardPayment = request.Appointment.CreditCardPayment;
                }
            }

            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = request.Appointment.Id }, request.Appointment));
        }
        private void setAppointmentDate(PersistAppointmentRequest request)
        {
            if (!request.Appointment.ConsultationTime.HasValue)
            {
                return;
            }
            var consultationDate = request.Appointment.ConsultationTime.Value;
            var slotTimeList     = request.Appointment.SlotTime.Split(new char[] { ':' });
            var hours            = slotTimeList?.Length > 0 ? Convert.ToInt32(slotTimeList[0]) : 0;
            var minutes          = slotTimeList?.Length > 0 ? Convert.ToInt32(slotTimeList[1]) : 0;

            var slotDateTime = new DateTime(consultationDate.Year, consultationDate.Month, consultationDate.Day, hours, minutes, 0);

            request.Appointment.ConsultationTime = slotDateTime;
        }