Ejemplo n.º 1
0
        public ActionResult GroupSms(int groupId, string msgBody)
        {
            if (ModelState.IsValid)
            {
                var members = db.UserGroups.Where(g => g.GroupID == groupId);
                var group   = db.Groups.Find(groupId);

                var groupedMessage = new GroupedMessage()
                {
                    GroupedMessageName = group.GroupName,
                    Type    = 1,
                    Message = msgBody,
                    Id      = Guid.NewGuid()
                };
                db.SaveChanges();
                db.GroupedMessages.Add(groupedMessage);

                foreach (var member in members)
                {
                    var message = new Message
                    {
                        UserId        = member.User.UserId,
                        msg_body      = msgBody,
                        Status        = 7,
                        ScheduledTime = DateTime.Now,
                        SentBy        = User.Identity.Name,
                        ParentGroupID = groupedMessage.Id
                    };
                    groupedMessage.Messages.Add(message);
                }
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = groupId }));
            }
            return(RedirectToAction("Details", new { id = groupId }));
        }
Ejemplo n.º 2
0
        public ActionResult Broadcast(string msgBody)
        {
            var id = Guid.Empty;

            if (ModelState.IsValid)
            {
                var members      = db.Users.Where(u => u.Status == 1);
                var broadcastMsg = new GroupedMessage()
                {
                    GroupedMessageName = "All",
                    Type          = 2,
                    Message       = msgBody,
                    TrrigeredTime = DateTime.Now,
                    Id            = Guid.NewGuid()
                };

                db.GroupedMessages.Add(broadcastMsg);
                foreach (var member in members)
                {
                    var message = new Message
                    {
                        UserId        = member.UserId,
                        msg_body      = msgBody,
                        Status        = 7,
                        ScheduledTime = DateTime.Now,
                        SentBy        = User.Identity.Name,
                        ParentGroupID = broadcastMsg.Id
                    };
                    broadcastMsg.Messages.Add(message);
                }
                db.SaveChanges();

                return(RedirectToAction("GroupedMessageDeatil", "Messages", new { id = broadcastMsg.Id }));
            }
            return(RedirectToAction("GroupedMessageDeatil", "Messages", new { id = id }));
        }