Exemple #1
0
        public ResponseEntity <long> AddGraphicMessage(GraphicMessage msg)
        {
            //msg.pic01 = string.IsNullOrEmpty(msg.pic01) ? string.Empty : ConfigurationManager.AppSettings["UploadUrl"] + msg.pic01;
            //msg.pic02 = string.IsNullOrEmpty(msg.pic02) ? string.Empty : ConfigurationManager.AppSettings["UploadUrl"] + msg.pic02;
            //msg.pic03 = string.IsNullOrEmpty(msg.pic03) ? string.Empty : ConfigurationManager.AppSettings["UploadUrl"] + msg.pic03;
            //msg.pic04 = string.IsNullOrEmpty(msg.pic04) ? string.Empty : ConfigurationManager.AppSettings["UploadUrl"] + msg.pic04;
            //msg.pic05 = string.IsNullOrEmpty(msg.pic05) ? string.Empty : ConfigurationManager.AppSettings["UploadUrl"] + msg.pic05;
            //msg.pic06 = string.IsNullOrEmpty(msg.pic06) ? string.Empty : ConfigurationManager.AppSettings["UploadUrl"] + msg.pic06;

            if (!string.IsNullOrEmpty(msg.poster) && msg.poster.IndexOf("base64,") > -1)
            {
                try
                {
                    var    img      = Utils.GetImageFromBase64(msg.poster.Substring(msg.poster.IndexOf("base64,") + 7));
                    string fileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg";
                    string fullPath = ConfigurationManager.AppSettings["UploadFolderPath"] + fileName;
                    img.Save(fullPath);

                    msg.poster = fileName;
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
            }


            ResponseEntity <long> response = new ResponseEntity <long>();

            var  dao     = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            bool success = true;
            long id      = 0;

            if (msg.id > 0)
            {
                dao.UpdateGraphicMessage(msg);
                id = msg.id;
            }
            else
            {
                id = (long)dao.AddGraphicMessage(msg);
            }


            if (success)
            {
                response = new ResponseEntity <long>(true, "添加图文成功", id);
            }
            else
            {
                response = new ResponseEntity <long>(true, "添加图文失败", id);
            }

            return(response);
        }
        public ResponseEntity <long> AddWeChatNews(GraphicMessage msg)
        {
            msg.isTop = false;
            if (!string.IsNullOrEmpty(msg.poster) && msg.poster.IndexOf("base64,") > -1)
            {
                try
                {
                    var    img      = Utils.GetImageFromBase64(msg.poster.Substring(msg.poster.IndexOf("base64,") + 7));
                    string fileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg";
                    string fullPath = ConfigurationManager.AppSettings["UploadFolderPath"] + fileName;
                    img.Save(fullPath);

                    msg.poster = fileName;
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
            }

            ResponseEntity <long> response = new ResponseEntity <long>();

            var  dao      = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            bool isExists = dao.MediaIdExist(msg.wechatMediaId);

            if (isExists)
            {
                response = new ResponseEntity <long>(true, "图文已存在", 0);
            }
            else
            {
                response = new ResponseEntity <long>(true, "图文导入成功", 0);
                dao.AddGraphicMessage(msg);
            }

            return(response);
        }