public override SentSmsModel Send(SmsModel message, IEnumerable <string> mobileNumbers) { var messageText = HttpUtility.UrlEncode(message.Message); using (var client = new WebClient()) { var numbers = new StringBuilder(); foreach (var number in mobileNumbers) { numbers.AppendFormat("{0},", number); } if (numbers.Length > 0) { numbers.Remove(numbers.Length - 1, 1); } var response = client.UploadValues("https://api.textlocal.in/send/", new NameValueCollection { { "apikey", GetSetting("API Key") }, { "numbers", numbers.ToString() }, { "message", messageText }, { "sender", GetSetting("Sender") }, { "format", "xml" } }); var result = new XmlDocument(); result.LoadXml(Encoding.UTF8.GetString(response)); var sentSms = new SentSmsModel(message, mobileNumbers); sentSms.IsSent = result.DocumentElement.SelectSingleNode("/response/status").InnerText.Trim().Equals("success"); sentSms.GatewayMessage = sentSms.IsSent ? null : result.DocumentElement.SelectSingleNode("/response/errors/error/message").InnerText.Trim(); return(sentSms); } }
public abstract SentSmsModel Send(SmsModel message, IEnumerable <string> mobileNumbers);
public SentSmsModel(SmsModel sms, IEnumerable <string> mobileNumbers) : this() { Message = sms.Message; Time = DateTime.Now; MobileNumbers = new ExtendedObservableCollection <string>(mobileNumbers); }