private static void TickIntervalCallbacks() { for (int i = 0; i < Utility.schedules.Count; i++) { if (--Utility.schedules[i].ticksLeft <= 0) { CallbackSchedule callback = Utility.schedules[i]; callback.ticksLeft = callback.intervalTicks; callback.action(); --callback.remainingCalls; if (callback.remainingCalls == 0) { Utility.schedules.RemoveAt(i); } if (i < Utility.schedules.Count) { if (callback != Utility.schedules[i]) { --i; } } } } }
public async Task <string> ScheduleCallAsync([FromBody] ScheduleCallDTO callInfo) { try { if (callInfo == null) { return("NotFound"); } //Widget wgt = context.Widgets.Find(Guid.Parse(callInfo.token)); //wgt.User = context.Users.Find(wgt.UserID); Widget wgt = await context.Widgets.Include(widget => widget.User) .Where(widget => widget.ID == Guid.Parse(callInfo.token)) .FirstOrDefaultAsync(); if (wgt == null) { return("NotFound"); } CallbackSchedule schedule = new CallbackSchedule(); schedule.widget = wgt; schedule.LeadName = callInfo.name; schedule.LeadEmail = callInfo.email; schedule.LeadMessage = callInfo.message ?? ""; schedule.LeadPhoneNumber = callInfo.phone; schedule.CallDone = false; schedule.EmailNotificationDone = false; schedule.ScheduledDateTime = ParseDateTime(callInfo.date, callInfo.time); context.CallbackSchedules.Add(schedule); await context.SaveChangesAsync(); try { EmailManager.SendCallNotificationEmail(wgt.DomainURL, wgt.NotificationEmail, wgt.User.Name, schedule.LeadName, schedule.LeadEmail, schedule.LeadPhoneNumber, schedule.ScheduledDateTime.ToString(), schedule.LeadMessage); }catch (Exception) { } return("OK: Call request sent"); }catch (Exception ex) { AppException exception = new AppException(); exception.ErrorDateTime = DateTime.Now; exception.Message = ex.Message; exception.FullString = ex.ToString(); context.AppExceptions.Add(exception); await context.SaveChangesAsync(); return("Error"); } }