public long AddDisplayGuideFile(T_BG_DisplayGuideFile displayGuideFile)
 {
     try
     {
         return(_bgDisplayGuideFileRepository.Add(displayGuideFile));
     }
     catch (Exception)
     {
         return(-1L);
     }
 }
 public bool UpdateDisplayGuideFile(T_BG_DisplayGuideFile displayGuideFile)
 {
     try
     {
         return(_bgDisplayGuideFileRepository.Update(displayGuideFile));
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public JsonDisplayGuideApiDelEntity DelDisplayGuide()
        {
            long id = CommonHelper.GetPostValue("id").ToLong(-1L);
            JsonDisplayGuideApiDelEntity json = new JsonDisplayGuideApiDelEntity();

            if (id < 0)
            {
                json.ErrorCode    = "E0001";
                json.ErrorMessage = "获得删除信息失败!";
                return(json);
            }
            T_BG_DisplayGuideFile file = _bgDisplayGuideFileService.GetBgDisplayGuideFile(id);

            if (file == null)
            {
                json.ErrorCode    = "E0002";
                json.ErrorMessage = "获得文件删除信息失败!";
                return(json);
            }
            string errorMsg;
            bool   delFile = FileHelper.DelFile(file.FilePath, out errorMsg);

            if (!delFile)
            {
                json.ErrorCode    = "E0003";
                json.ErrorMessage = "删除本地文件失败!";
                return(json);
            }
            bool result = _bgDisplayGuideFileService.DelGuideFileAndUploadFile(file.FileNewName);

            if (!result)
            {
                json.ErrorCode    = "E0004";
                json.ErrorMessage = "删除数据库信息失败!";
            }
            else
            {
                json.ErrorCode    = "E0000";
                json.ErrorMessage = "删除成功!";
            }
            return(json);
        }
        public JsonResult SaveGuideFile()
        {
            long   id             = CommonHelper.GetPostValue("id").ToLong(-1L);
            string title          = CommonHelper.GetPostValue("title");
            string time           = CommonHelper.GetPostValue("time");
            string fileoriginname = CommonHelper.GetPostValue("fileoriginname");
            string filenewname    = CommonHelper.GetPostValue("filenewname");
            string filepath       = CommonHelper.GetPostValue("filepath");
            string filetype       = CommonHelper.GetPostValue("filetype");;

            title          = HttpUtility.UrlDecode(title);
            fileoriginname = HttpUtility.UrlDecode(fileoriginname);
            filepath       = HttpUtility.UrlDecode(filepath);
            JsonGuideFleSaveEntity json = new JsonGuideFleSaveEntity();

            if (string.IsNullOrEmpty(time) || string.IsNullOrEmpty(fileoriginname) || string.IsNullOrEmpty(filenewname) || string.IsNullOrEmpty(filepath) || string.IsNullOrEmpty(filetype))
            {
                json.ErrorCode    = "E001";
                json.ErrorMessage = "参数不全!";
                return(Json(json));
            }

            T_BG_DisplayGuideFile displayGuideFile = new T_BG_DisplayGuideFile
            {
                Title          = title,
                FileNewName    = filenewname,
                FileOriginName = fileoriginname,
                FilePath       = filepath,
                FileType       = filetype,
                UserId         = LoginHelper.UserId,
                PublishTime    = time.ToDateTime(DateTime.MinValue),
                AddTime        = DateTime.Now,
                IsDel          = 0
            };

            bool result;

            if (id > 0)
            {
                T_BG_DisplayGuideFile file = _bgDisplayGuideFileService.GetBgDisplayGuideFile(id);
                if (file == null)
                {
                    json.ErrorCode    = "E001";
                    json.ErrorMessage = "参数不全!";
                    return(Json(json));
                }
                displayGuideFile.Id = file.Id;
                if (!file.FilePath.Equals(filepath, StringComparison.InvariantCultureIgnoreCase))
                {
                    //上传表里的数据也应该删除T_BG_UpFiles
                    string msg;
                    bool   del = FileHelper.DelFile(file.FilePath, out msg);
                    if (!del)
                    {
                        json.ErrorCode    = "E002";
                        json.ErrorMessage = "删除本地的文件失败!";
                        return(Json(json));
                    }
                    bool delResult = _bgUpFilesService.DelFileByFileNewName(filenewname);
                    if (!delResult)
                    {
                        json.ErrorCode    = "E002";
                        json.ErrorMessage = "删除T_BG_UpFiles记录的文件失败!";
                        return(Json(json));
                    }
                }
                result = _bgDisplayGuideFileService.UpdateDisplayGuideFile(displayGuideFile);
            }
            else
            {
                result = _bgDisplayGuideFileService.AddDisplayGuideFile(displayGuideFile) > 0;
            }

            if (result)
            {
                json.ErrorCode    = "E000";
                json.ErrorMessage = "保存成功!";
            }
            else
            {
                json.ErrorCode    = "E002";
                json.ErrorMessage = "保存失败!";
            }
            return(Json(json));
        }