I have a controller method which is responsible for scheduling appointments. I'm looking to schedule a task to remind the user via SMS (twilio) 5 minutes before their appointment to login to the service.
Here is my method call:
private SMSNotifier sms = new SMSNotifier();
BackgroundJob.Schedule( () => sms.SendPatientUpcomingApptNotificationTest(appointment), appointment.Start.AddMinutes(-5));
and here is my class:
public SMSNotifier()
{
var accountSid = ConfigurationManager.AppSettings["TwilioSid"];
// Your Auth Token from twilio.com/console
var authToken = ConfigurationManager.AppSettings["TwilioToken"]; ;
TwilioClient.Init(accountSid, authToken);
}
public void SendPatientUpcomingApptNotificationTest(Appointment appt)
{
var message = MessageResource.Create(
to: new PhoneNumber("+xxxxxxxxxx"),
from: new PhoneNumber("+xxxxxxxxxx"),
body: string.Format("Hello {0} {1}! You have an upcoming web based video appointment with xxxxxxxxxx. Please login to the website to be seen. Your appointment time is: {2} Thank you - xxxxxxxx", "xxxxxxx", "xxxxxxxx", appt.Start));
}
}
I keep getting this error:
Server Error in '/' Application.
Self referencing loop detected for property 'User' with type 'System.Data.Entity.DynamicProxies.AspNetUser_80E6332CC002F8FCF589159A68E74A0922BEE992586B9FE280D950E149CCC7EB'. Path 'Patient.ActiveSessions[0]'.
But I just don't understand why. I don't reference a User object anywhere.
I should mention I obviously googled that error:
None of this provided any progress. I still have the same error.
What do you guys think?
I definitely think it has to do with the way I'm trying to schedule the 'SendPatientUpcomingApptNotificationTest' method. I can do a Console.WriteLine and it queues the job fine.
IE:
BackgroundJob.Schedule( () => Console.WriteLine("TestSchedule"), appointment.Start.AddMinutes(-5));
Works perfectly