示例#1
0
        public async Task <string> CheckScheduledCallback()
        {
            try
            {
                DateTime now = DateTime.Parse(GetUKDateTime());
                List <CallbackSchedule> email_schedules = await context.CallbackSchedules.Include(c => c.widget)
                                                          .Include(c => c.widget.User)
                                                          .Where(c => c.EmailNotificationDone == false).ToListAsync();

                foreach (CallbackSchedule cs in email_schedules)
                {
                    if (now.AddMinutes(15) >= cs.ScheduledDateTime)
                    {
                        try
                        {
                            //send email notification

                            EmailManager.SendCallNotificationEmail(cs.widget.DomainURL, cs.widget.NotificationEmail, cs.widget.User.Name, cs.LeadName, cs.LeadEmail, cs.LeadPhoneNumber, cs.ScheduledDateTime.ToString(), cs.LeadMessage);

                            cs.EmailNotificationDone = true;
                            await context.SaveChangesAsync();
                        }catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }


                List <CallbackSchedule> call_schedules = await context.CallbackSchedules.Include(c => c.widget)
                                                         .Where(c => c.CallDone == false).ToListAsync();

                foreach (CallbackSchedule cs in call_schedules)
                {
                    if (now >= cs.ScheduledDateTime)
                    {
                        try
                        {
                            //do callback

                            string response = await Call(cs.widget.ID, cs.LeadPhoneNumber, cs.widget.AuthKey, cs.widget.Extension, cs.LeadName, 1);

                            cs.CallDone = true;
                            await context.SaveChangesAsync();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }

                return("OK");
            }catch (Exception ex)
            {
                return(DateTime.Now.ToString() + ": " + ex.Message);
            }
        }
示例#2
0
        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");
            }
        }