///<summary>Surround with Try/Catch. Sent as time sensitive message. Returns an instance of the new SmsToMobile row.</summary> public static SmsToMobile SendSmsSingle(long patNum, string wirelessPhone, string message, long clinicNum, SmsMessageSource smsMessageSource, bool makeCommLog = true, Userod user = null, bool canCheckBal = true) { //No need to check RemotingRole; no call to db. if (Plugins.HookMethod(null, "SmsToMobiles.SendSmsSingle_start", patNum, wirelessPhone, message, clinicNum)) { return(null); } double balance = SmsPhones.GetClinicBalance(clinicNum); if (balance - CHARGE_PER_MSG < 0 && canCheckBal) //ODException.ErrorCode 1 will be processed specially by caller. { throw new ODException("To send this message first increase spending limit for integrated texting from eServices Setup.", 1); } string countryCodeLocal = CultureInfo.CurrentCulture.Name.Substring(CultureInfo.CurrentCulture.Name.Length - 2); //Example "en-US"="US" string countryCodePhone = SmsPhones.GetFirstOrDefault(x => x.ClinicNum == clinicNum)?.CountryCode ?? ""; SmsToMobile smsToMobile = new SmsToMobile(); smsToMobile.ClinicNum = clinicNum; smsToMobile.GuidMessage = Guid.NewGuid().ToString(); smsToMobile.GuidBatch = smsToMobile.GuidMessage; smsToMobile.IsTimeSensitive = true; smsToMobile.MobilePhoneNumber = ConvertPhoneToInternational(wirelessPhone, countryCodeLocal, countryCodePhone); smsToMobile.PatNum = patNum; smsToMobile.MsgText = message; smsToMobile.MsgType = smsMessageSource; SmsToMobiles.SendSms(new List <SmsToMobile>() { smsToMobile }); //Will throw if failed. HandleSentSms(new List <SmsToMobile>() { smsToMobile }, makeCommLog, user); return(smsToMobile); }
///<summary>Surround with try/catch. Returns true if all messages succeded, throws exception if it failed.</summary> public static void SendSmsMany(List <SmsToMobile> listMessages, bool makeCommLog = true, Userod user = null, bool canCheckBal = true) { //No need to check RemotingRole; no call to db. if (listMessages == null || listMessages.Count == 0) { return; } if (canCheckBal) { foreach (long clinicNum in listMessages.Select(x => x.ClinicNum)) { double balance = SmsPhones.GetClinicBalance(clinicNum); if (balance - (CHARGE_PER_MSG * listMessages.Count(x => x.ClinicNum == clinicNum)) < 0) { //ODException.ErrorCode 1 will be processed specially by caller. throw new ODException("To send these messages first increase spending limit for integrated texting from eServices Setup.", 1); } } } SendSms(listMessages); HandleSentSms(listMessages, makeCommLog, user); }