예제 #1
0
        public static void QueueSms(IQueryable <Person> q, int iSendGroupID, string sTitle, string sMessage)
        {
            // Create new SMS send list
            var list = new SMSList();

            list.Created     = DateTime.Now;
            list.SendAt      = DateTime.Now;
            list.SenderID    = Util.UserPeopleId ?? 1;
            list.SendGroupID = iSendGroupID;
            list.Title       = sTitle;
            list.Message     = sMessage;

            DbUtil.Db.SMSLists.InsertOnSubmit(list);
            DbUtil.Db.SubmitChanges();

            // Load all people but tell why they can or can't be sent to

            foreach (var i in q)
            {
                var item = new SMSItem();

                item.ListID   = list.Id;
                item.PeopleID = i.PeopleId;

                if (!string.IsNullOrEmpty(i.CellPhone))
                {
                    item.Number = i.CellPhone;
                }
                else
                {
                    item.Number   = "";
                    item.NoNumber = true;
                }

                if (!i.ReceiveSMS)
                {
                    item.NoOptIn = true;
                }

                DbUtil.Db.SMSItems.InsertOnSubmit(item);
            }

            DbUtil.Db.SubmitChanges();

            // Check for how many people have cell numbers and want to receive texts
            var qSMS = from p in q
                       where p.CellPhone != null
                       where p.ReceiveSMS
                       select p;

            var countSMS = qSMS.Count();

            // Add counts for SMS, e-Mail and none
            list.SentSMS  = countSMS;
            list.SentNone = q.Count() - countSMS;

            DbUtil.Db.SubmitChanges();

            ProcessQueue(list.Id);
        }
예제 #2
0
        private async Task <SMSList> GetRecords(SMSFilter filter = null)
        {
            filter = filter == null ? new SMSFilter() : filter;
            List <ShortMessageService> dbRec = new List <ShortMessageService>();

            if (!filter.StartDate.HasValue || !filter.EndDate.HasValue)
            {
                dbRec = await _context.ShortMessageService.Where(d => ((!string.IsNullOrWhiteSpace(filter.ApplicationUserId) && d.CreatedBy == filter.ApplicationUserId) ||
                                                                       (string.IsNullOrWhiteSpace(filter.ApplicationUserId) && (filter.AllRecord || (!filter.AllRecord && d.CreatedBy == _userHandler.User.Id)))) &&
                                                                 (filter.SMSStatus == -1 || (filter.SMSStatus != -1 && filter.SMSStatus == (int)d.SMSStatus))).OrderByDescending(m => m.ModifiedOn).Take(1000).ToListAsync();
            }
            else
            {
                dbRec = await _context.ShortMessageService.Where(d => ((!string.IsNullOrWhiteSpace(filter.ApplicationUserId) && d.CreatedBy == filter.ApplicationUserId) ||
                                                                       (string.IsNullOrWhiteSpace(filter.ApplicationUserId) && (filter.AllRecord || (!filter.AllRecord && d.CreatedBy == _userHandler.User.Id)))) &&
                                                                 d.CreatedOn.HasValue && d.CreatedOn.Value.Date >= filter.StartDate.Value.Date && d.CreatedOn.Value.Date <= filter.EndDate.Value.Date &&
                                                                 (filter.SMSStatus == -1 || (filter.SMSStatus != -1 && filter.SMSStatus == (int)d.SMSStatus))).OrderByDescending(m => m.ModifiedOn).ToListAsync();
            }
            SMSList recList = new SMSList
            {
                UserHandler = _userHandler,
                Records     = _mapper.Map <List <ShortMessageService>, List <SMSModel> >(dbRec)
            };

            return(recList);
        }
예제 #3
0
        public static string SendSmsReplyIncoming(CMSDataContext db, int receivedId,
                                                  Person p, string toNumber, SMSNumber fromNumber, string title, string message)
        {
            string sSid   = GetSid(db);
            string sToken = GetToken(db);

            var list = new SMSList
            {
                Created     = DateTime.Now,
                SendAt      = DateTime.Now,
                SenderID    = db.UserPeopleId ?? 1,
                SendGroupID = fromNumber.GroupID,
                Title       = title,
                Message     = message,
                ReplyToId   = receivedId
            };
            var item = new SMSItem
            {
                ListID   = list.Id,
                PeopleID = p?.PeopleId,
                Number   = toNumber,
            };

            list.SMSItems.Add(item);

            var r = new TextReplacements(db, message);

            if (item.PeopleID != null)
            {
                message = r.DoReplacements(item);
            }
            var response = SendSmsInternal(sSid, sToken, fromNumber.Number, toNumber, message);

            var succeeded = !IsSmsFailed(response);

            if (succeeded)
            {
                list.SentSMS = 1;
                item.Sent    = true;
            }
            db.SMSLists.InsertOnSubmit(list);
            db.SubmitChanges();
            if (succeeded)
            {
                db.Connection.Execute(
                    "update dbo.SmsReceived set RepliedTo = @replied where id = @id",
                    new { replied = true, id = receivedId });
            }
            return(ResultMessage(response, toNumber));
        }
예제 #4
0
        public static void QueueSms(Guid iQBID, int iSendGroupID, string sTitle, string sMessage)
        {
            var q = DbUtil.Db.PeopleQuery(iQBID);

            // Create new SMS send list
            var list = new SMSList();

            list.Created = DateTime.Now;
            list.SendAt = DateTime.Now;
            list.SenderID = Util.UserPeopleId ?? 1;
            list.SendGroupID = iSendGroupID;
            list.Title = sTitle;
            list.Message = sMessage;

            DbUtil.Db.SMSLists.InsertOnSubmit(list);
            DbUtil.Db.SubmitChanges();

            // Load all people but tell why they can or can't be sent to

            foreach (var i in q)
            {
                var item = new SMSItem();

                item.ListID = list.Id;
                item.PeopleID = i.PeopleId;

                if (!string.IsNullOrEmpty(i.CellPhone))
                {
                    item.Number = i.CellPhone;
                }
                else
                {
                    item.Number = "";
                    item.NoNumber = true;
                }

                if (!i.ReceiveSMS)
                {
                    item.NoOptIn = true;
                }

                DbUtil.Db.SMSItems.InsertOnSubmit(item);
            }

            DbUtil.Db.SubmitChanges();

            // Check for how many people have cell numbers and want to receive texts
            var qSMS = from p in q
                       where p.CellPhone != null
                       where p.ReceiveSMS
                       select p;

            var countSMS = qSMS.Count();

            // Add counts for SMS, e-Mail and none
            list.SentSMS = countSMS;
            list.SentNone = q.Count() - countSMS;

            DbUtil.Db.SubmitChanges();

            ProcessQueue(list.Id);
        }
예제 #5
0
        private static void QueueSms(CMSDataContext db, IQueryable <Person> q, int iSendGroupID, string sTitle, string sMessage, DateTime?schedule)
        {
            // Create new SMS send list
            var list = new SMSList();

            var now = DateTime.Now;

            list.Created     = now;
            list.SendAt      = schedule ?? now;
            list.SenderID    = db.UserPeopleId ?? 1;
            list.SendGroupID = iSendGroupID;
            list.Title       = sTitle;
            list.Message     = sMessage;

            db.SMSLists.InsertOnSubmit(list);
            db.SubmitChanges();

            // Load all people but tell why they can or can't be sent to

            var personOptouts = from person in q
                                select new
            {
                person,
                optOutGroup = person.SmsGroupOptOuts.Any(vv => vv.FromGroup == iSendGroupID)
            };

            foreach (var personOptout in personOptouts)
            {
                var item = new SMSItem {
                    ListID = list.Id, PeopleID = personOptout.person.PeopleId
                };

                if (!string.IsNullOrEmpty(personOptout.person.CellPhone))
                {
                    item.Number = personOptout.person.CellPhone;
                }
                else
                {
                    item.Number   = "";
                    item.NoNumber = true;
                }
                if (!personOptout.person.ReceiveSMS || personOptout.optOutGroup)
                {
                    item.NoOptIn = true;
                }
                db.SMSItems.InsertOnSubmit(item);
            }

            list.ReadyToSend = true;
            db.SubmitChanges();

            // Check for how many people have cell numbers and want to receive texts
            var qSMS = from personOptout in personOptouts
                       where personOptout.person.CellPhone != null
                       where personOptout.person.ReceiveSMS
                       where !personOptout.optOutGroup
                       select personOptout.person;

            var countSMS = qSMS.Count();

            // Add counts for SMS, e-Mail and none
            list.SentSMS  = countSMS;
            list.SentNone = q.Count() - countSMS;

            db.SubmitChanges();

            if (list.SendAt <= now)
            {
                if (Util.IsDebug())
                {
                    ProcessQueue(db, list.Id);
                }
                else
                {
                    ExecuteCmsTwilio(list.Id, db.Host);
                }
            }
        }
예제 #6
0
 public SmsSentDetailsModel(CMSDataContext db, int id)
 {
     CurrentDatabase = db;
     SmsList         = CurrentDatabase.SMSLists.Single(vv => vv.Id == id);
 }