public string AutoSentMessage(string createdon = "") { try { Settings_BLL settings_BLL = new Settings_BLL(); Schedules_BLL schedules_BLL = new Schedules_BLL(); //Determine Start and End Date based on today's date? //var StartDate = body.Get("startdate") == null ? DateTime.MinValue : Convert.ToDateTime(body["startdate"].ToString()).AddHours(Repo.SubtractLocalTimeZone); //var EndDate = body.Get("enddate") == null ? DateTime.MinValue : Convert.ToDateTime(body["enddate"].ToString()).AddHours(Repo.SubtractLocalTimeZone); ////Determine how many winners to pick? //var NoOfWinners = body.Get("noofrecords") == null ? 0 : Convert.ToInt32(body["noofrecords"].ToString()); DateTime localNow = (createdon == "") ? DateTime.UtcNow : Convert.ToDateTime(createdon); //get all setting where local now == set time List <Settings> runningSettings = settings_BLL.getSettingsByDateTime(localNow); //foreach list of setting, get all schedules where isSent = 0 foreach (var item in runningSettings) { List <Schedules> upcomingSchedules = schedules_BLL.getAllUpcomingSchedulesByAppId(item.AppId); //foreach schedules , send SMS and set isSent = 0, SentOn = localNow foreach (var it in upcomingSchedules) { if (it.EventDate.AddHours(Repo.AddLocalTimeZone).Date == DateTime.UtcNow.Date) { GeneralFunctions.SendSms(Convert.ToInt32(item.AppId), new Guid(item.AppSecret), it.MobileNo, item.MessageTemplate.Replace("{custom1}", it.Custom1).Replace("{custom2}", it.Custom2).Replace("{custom3}", it.Custom3)); //update isSent and sentOn it.IsSent = true; it.SentOn = localNow; schedules_BLL.update(it); } } } return("OK"); } catch (Exception ex) { return(ex.Message); } }