예제 #1
0
        private List<TextMessage> SendToMembersOfGroupsUserIsLeaderOf(SmsRequestExtended request, SmsPerson dbPerson)
        {
            var leaderGroups = dbPerson.SmsGroupLeaders.Select(m => m.SmsGroup.Id).ToList();
            var groups =
                    _uow.SmsGroups.Find(g => leaderGroups.Contains(g.Id)).Include("SmsGroupMembers.SmsPerson").ToList();

            List<TextMessage> messages = new List<TextMessage>();
            foreach (var g in groups)
            {
                foreach (var m in g.SmsGroupMembers.Where(member => member.SmsPersonId != dbPerson.Id))
                {
                    messages.Add(new TextMessage { Request = request, ToPerson = m.SmsPerson, FromPerson = dbPerson });
                }
            }
            return messages;
        }
예제 #2
0
 public void SavePerson(SmsPerson person)
 {
     if (person.Id == default(int))
     {
         _uow.SmsPerson.Add(person);
     }
     else
     {
         var dbPerson = GetPerson(person.Id);
         dbPerson.Name = person.Name;
         dbPerson.PhoneNumber = person.PhoneNumber;
         dbPerson.Active = person.Active;
     }
     _uow.SaveChanges();
 }
예제 #3
0
        private void SendSms(SmsRequestExtended request, SmsPerson person)
        {
            var twilio = new TwilioRestClient(AccountSid, TwilioAuthToken);
            var message = twilio.SendMessage(TwilioNumber, "+1" + person.PhoneNumber, request.Body, @"http://benjaminjanderson.com/smslistener.ashx");

            _uow.SmsLogs.Add(new SmsLog
            {
                Message = request.Body,
                SmsDate = DateTime.UtcNow,
                MessageType = SmsMessageType.Sent,
                SmsPersonId = person.Id,
                MessageId = message.Sid,
                MessageStatus = "Sending",
            });
            _uow.SaveChanges();
        }
예제 #4
0
        private int SendToMembersOfGroupsUserIsLeaderOf(SmsRequestExtended request, SmsPerson dbPerson)
        {
            int messageSentCount = 0;
            var leaderGroups = dbPerson.SmsGroupLeaders.Select(m => m.SmsGroup.Id).ToList();
            var groups = _uow
                .SmsGroups
                .Find(g => leaderGroups.Contains(g.Id))
                .Include("SmsGroupMembers.SmsPerson")
                .ToList();

            foreach (var g in groups)
            {
                foreach (var m in g.SmsGroupMembers)
                {
                    SendSms(request, m.SmsPerson);
                    messageSentCount++;
                }
            }
            return messageSentCount;
        }
예제 #5
0
 public ActionResult Person(SmsPerson person)
 {
     _message.SavePerson(person);
     return Redirect(Url.Action("Index", "Messaging"));
 }