public ActionResult SendShiftFillAlert(int shiftID) { var client = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken); var optinEmployees = _employeeRepository.Select().Where(e => e.AvailableShiftsNotificationSmsOptIn == true); var openShift = _shiftRepository.Select().Where(s => s.ID == shiftID).FirstOrDefault(); var message = string.Format( "An open shift starting at {0} and ending at {1} is available on {2}. To fill this open shift reply with the message: 'yes {3}'", openShift.StartTime.ToShortTimeString(), openShift.EndTime.ToShortTimeString(), openShift.StartTime.ToShortDateString(), openShift.ID); int sentMessageCounter = 0; foreach (var employee in optinEmployees) { var result = client.SendMessage(callerid, employee.PhoneNumber, message); if (result.RestException != null) { //TODO: log this error } { sentMessageCounter++; } } return(Json(new { shiftid = openShift.ID, messagesSentCount = sentMessageCounter })); }