public ActionResult Save(PushMessageModel model, string pushIds)
        {
            var message = new ReturnMessage {
                Success = false, Msg = "操作失败!"
            };

            try
            {
                PushMessageBusiness business = new PushMessageBusiness();
                if (string.IsNullOrEmpty(pushIds))       //单条编辑
                {
                    var pushMessage = business.GetFromCache(model.PushId);
                    if (pushMessage == null)
                    {
                        message.Msg = "推送消息不存在!";
                        return(Content(JsonConvert.SerializeObject(message)));
                    }
                    pushMessage.MessagePriority = model.MessagePriority;
                    pushMessage.MessageType     = model.MessageType;
                    pushMessage.PushData        = model.PushData;
                    pushMessage.PushStatus      = model.PushStatus;
                    pushMessage.NextPushTime    = model.NextPushTime;
                    pushMessage.PushCount       = model.PushCount;
                    pushMessage.Memo            = string.Empty;
                    message.Success             = business.Edit(pushMessage);
                }
                else
                {
                    //批量编辑
                    PushMessageCondition condition = new PushMessageCondition();
                    condition.PushIds = new List <string>(pushIds.Split(','));
                    var data = business.GetPushMessageList(condition);
                    data.ForEach(t =>
                    {
                        t.NextPushTime   = model.NextPushTime;
                        t.PushCount      = model.PushCount;
                        t.LastModifyTime = DateTime.Now;
                        t.PushStatus     = PushStatusEnum.UnPush;
                    });
                    if (data.Count > 0)
                    {
                        message.Success = business.EditPushMessage(data);
                    }
                }
            }
            catch (Exception)
            {
            }
            return(Content(JsonConvert.SerializeObject(message)));
        }
Beispiel #2
0
        public void TestSendPushMessage()
        {
            SendMessageBusiness sendBus = new SendMessageBusiness();
            PushMessageBusiness pushBus = new PushMessageBusiness();

            List <PushMessageModel> list = new List <PushMessageModel>();

            list.Add(pushBus.GetFromCache("0907396caecb4ce9be68362b07276e64"));
            foreach (PushMessageModel m in list)
            {
                if (m.NextPushTime <= DateTime.Now)
                {
                    PushMessage pushDTO = MappingHelper.From <PushMessage, PushMessageModel>(m);
                    //notifyBus.SendPushMessage(pushDTO);
                    sendBus.Send(pushDTO, sendBus.Callback);
                }
            }
            Thread.Sleep(100000);
        }