public JsonResult DelMessage(string id)
        {
            WX_Message wm = WX_MessageService.instance().Single(new Guid(id));

            if (wm != null)
            {
                WX_MessageGroupService.instance().DeleteByMID(new Guid(id));
                WX_MessageService.instance().Delete(new Guid(id));
            }
            return(Json("ok", JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetMessagePage(int pageIndex, int pageSize, string wheres, string sortorder, string sortname)
        {
            int totalcount = 0;
            IEnumerable <WX_Message> datalist = WX_MessageService.instance().GetPageByDynamic(pageIndex, pageSize, out totalcount, sortname, sortorder, wheres);

            datalist.Each(m =>
            {
                m.Groups = WX_MessageGroupService.instance().GetEnumByMessID(m.ID).OrderBy(n => n.Short);
            });
            ResultBase_Page page = new ResultBase_Page(pageIndex, pageSize, totalcount);

            page.content = datalist.ToList();
            return(Json(page, JsonRequestBehavior.AllowGet));
        }
        public ActionResult TextMessage_Create(string id)
        {
            WX_Message m;

            if (string.IsNullOrEmpty(id))
            {
                m = new WX_Message();
            }
            else
            {
                m = WX_MessageService.instance().Single(new Guid(id));
            }
            return(View(m));
        }
 public JsonResult TextMessage_Create(string title, string id, List <WX_MessageGroup> list)
 {
     if (new Guid(id) == Guid.Empty)
     {
         WX_Message wm = new WX_Message()
         {
             ID         = Guid.NewGuid(),
             CreateTime = DateTime.Now
         };
         wm.CompanyID = UserDateTicket.Company.ID;
         wm.ConfigID  = UserDateTicket.wx_config.ID;
         wm.Title     = title;
         if (WX_MessageService.instance().Insert(wm) == 1)
         {
             foreach (var item in list)
             {
                 Files f = FilesService.instance().Single(item.FilesID);
                 item.MessageID    = wm.ID;
                 item.ImgUrl       = f.FilePath;
                 item.Content      = Server.UrlDecode(item.Content);
                 item.Img_media_id = f.media_id;
                 WX_MessageGroupService.instance().Insert(item);
             }
         }
     }
     else
     {
         WX_MessageGroupService.instance().DeleteByMID(new Guid(id));
         WX_Message wm = WX_MessageService.instance().Single(new Guid(id));
         wm.media_id = "";
         wm.Title    = title;
         WX_MessageService.instance().Update(wm);
         foreach (var item in list)
         {
             Files f = FilesService.instance().Single(item.FilesID);
             item.MessageID    = wm.ID;
             item.ImgUrl       = f.FilePath;
             item.Img_media_id = f.media_id;
             item.Content      = Server.UrlDecode(item.Content);
             WX_MessageGroupService.instance().Insert(item);
         }
     }
     return(Json("ok", JsonRequestBehavior.AllowGet));
 }
 public JsonResult GetOnlieMessage()
 {
     return(Json(WX_MessageService.instance().GetEnumByCID(UserDateTicket.Company.ID).Where(m => !string.IsNullOrEmpty(m.media_id)), JsonRequestBehavior.AllowGet));
 }
        public JsonResult AsyncMessage()
        {
            Hashtable hash = new Hashtable();
            IEnumerable <WX_Message> Messages = WX_MessageService.instance().GetEnumByCID(UserDateTicket.Company.ID);

            foreach (var item in Messages)
            {
                StringBuilder ArticlesJson = new StringBuilder();

                if (string.IsNullOrEmpty(item.media_id))
                {
                    ArticlesJson.Append(WXApiJson.GetArticlesJsonStr(item.ID));
                    string msg = WXApi.Material_add_news(GetToken(), ArticlesJson.ToString());

                    if (Utils.GetJsonValue(msg, "errcode") != "")
                    {
                        hash["code"]    = 0;
                        hash["errcode"] = Utils.GetJsonValue(msg, "errcode");
                        hash["errmsg"]  = Utils.GetJsonValue(msg, "errmsg");
                        return(Json(hash, JsonRequestBehavior.AllowGet));
                    }
                    string media_id = Utils.GetJsonValue(msg, "media_id");

                    string backInfo = WXApi.Material_get(GetToken(), "{\"media_id\":\"" + media_id + "\"}");
                    if (Utils.GetJsonValue(backInfo, "errcode") != "")
                    {
                        hash["code"]    = 0;
                        hash["errcode"] = Utils.GetJsonValue(msg, "errcode");
                        hash["errmsg"]  = Utils.GetJsonValue(msg, "errmsg");
                        return(Json(hash, JsonRequestBehavior.AllowGet));
                    }

                    var serializer = JsonSerializer.Create();
                    var obj        = serializer.Deserialize(new JsonTextReader(new StringReader(backInfo))) as JObject;
                    var data       = obj["news_item"];
                    for (int i = 0; i < item.Groups.Count(); i++)
                    {
                        if (string.IsNullOrEmpty(item.Groups.ToList()[i].URL))
                        {
                            item.Groups.ToList()[i].URL = JsonHelper.GetJsonValue(data[i].ToString(), "url");
                            WX_MessageGroupService.instance().Update(item.Groups.ToList()[i]);
                        }
                    }
                    item.media_id = media_id;
                    WX_MessageService.instance().Update(item);
                }
            }
            hash["code"] = 1;
            return(Json(hash, JsonRequestBehavior.AllowGet));

            //if (Utils.GetJsonValue(msg, "errcode") == "0")
            //{
            //    return Json(new { code = 1, msg = "" }, JsonRequestBehavior.AllowGet);// "{\"code\":1,\"msg\":\"\"}";
            //}
            //else
            //{
            //    return Json(new
            //    {
            //        code = 0,
            //        msg = "errcode:" +
            //            Utils.GetJsonValue(msg, "errcode") +
            //            ", errmsg:" + Utils.GetJsonValue(msg, "errmsg")
            //    }, JsonRequestBehavior.AllowGet);
            //}
        }
 public JsonResult GetMessage(string id)
 {
     return(Json(WX_MessageService.instance().Single(new Guid(id)), JsonRequestBehavior.AllowGet));
 }