public IHttpActionResult SendSmsMessageForVehicles(SmsVehicleModel model)
        {
            if (String.IsNullOrEmpty(model.Text))
            {
                return Ok("Enter SMS text, please.");
            }
            if (model.Vehicles.Count() <= 0)
            {
                return Ok("Choose vehicles, please.");
            }

            var phones = model.Vehicles.Select(x => x.PhoneNumber).Distinct();
            //var phones = String.Join(",", phoneNumbers);

            if (phones.Count() > 0)
            {
                var data = new SmsDto { Text = model.Text, Phones = phones.ToList() };
                _service.SendSms(data);
            }

            return Ok();
        }
Ejemplo n.º 2
0
        public void SendSms(SmsDto model)
        {
            try
            {
                SMSC smsc = new SMSC();

                var senderSMSLimit = Configuration.SendSMSLimit;
                var totalSends = model.Phones.Count() / senderSMSLimit;

                for (int i = 0; i <= totalSends; i++)
                {
                    var phonesForSend = model.Phones.Skip(i * senderSMSLimit).Take(senderSMSLimit);
                    var phonesForSendString = String.Join(",", phonesForSend);
                    if (!String.IsNullOrEmpty(phonesForSendString))
                    {
            #if !DEBUG
                        smsc.send_sms(phonesForSendString, model.Text, sender: Configuration.SmsSender);
            #endif
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }