public ActionResult SendSMS(SmsViewModel model) { if (ModelState.IsValid) { var studentList = Db.AssignedClasses.Where(x => x.ClassName.Equals(model.ClassName) && x.TermName.Equals(model.Term.ToString()) && x.SessionName.Equals(model.Session) && x.SchoolId.Equals(userSchool)) .Select(y => y.StudentId).ToList(); foreach (var student in studentList) { var guardianNumber = Db.Students.Where(s => s.StudentId.Equals(student)).Select(x => x.PhoneNumber).ToList(); foreach (var guardian in guardianNumber) { //var guardianContact = Db.Guardians.Where(x => x.GuardianEmail.Equals(guardian)) // .Select(y => y.PhoneNumber).FirstOrDefault(); SMS sms = new SMS() { SenderId = model.SenderId, Message = model.Message, Numbers = guardian }; try { bool isSuccess = false; string errMsg = null; string response = _smsService.Send(sms); //Send sms string code = _smsService.GetResponseMessage(response, out isSuccess, out errMsg); if (!isSuccess) { ModelState.AddModelError("", errMsg); } else { ViewBag.Message = "Message was successfully sent."; } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } } } return(View(model)); }
public Task SendAsync(IdentityMessage message) { // Plug in your SMS service here to send a text message. var _smsService = new SmsServiceTemp(); string body = message.Body; string destination = message.Destination; var sms = new Sms() { Sender = "AJAOKO", Message = body, Recipient = destination }; bool isSuccess = false; string errMsg = null; string response = _smsService.Send(sms); //Send sms string code = _smsService.GetResponseMessage(response, out isSuccess, out errMsg); if (!isSuccess) { isSuccess = false; } else { isSuccess = true; } return(Task.FromResult(true)); }