public string Create(ArticleEntity article) { if (ModelState.IsValid) { ArticleBLL articleBLL = new ArticleBLL(); article.ArticleTitle = article.ArticleTitle.UrlDecode(); //文章标题 article.ArticleTitleAlias = article.ArticleTitleAlias.UrlDecode(); article.ArticleContent = article.ArticleContent.UrlDecode(); //文章内容 article.CreateTime = DateTime.Now; articleBLL.AddArticleEntity(article); //Step2 维护文章和期刊的关系 if (article.JournalId.HasValue) { JournalArticleRelationEntity journalArticleRelationEntity = new JournalArticleRelationEntity(); journalArticleRelationEntity.JournalId = article.JournalId;//期刊Id journalArticleRelationEntity.ArticleId = article.Id; JournalArticleRelationBLL journalArticleRelationBLL = new JournalArticleRelationBLL(); journalArticleRelationBLL.AddJournalArticleRelationEntity(journalArticleRelationEntity); articleBLL.UpdateArticlePropertyIdByID(journalArticleRelationEntity.Id, article.Id); } //Step3 维护照片关系 this.ArticleImageSave(article); //if (article.ImgFileList != null) //{ // ArticleImageBLL articleImageBLL = new ArticleImageBLL(); // int j = 1; // for (int i = 0; i < article.ImgFileList.Count; i++) // { // string savePath = System.Web.HttpContext.Current.Server.MapPath("~"); // string fromPath = savePath + ConfigurationManager.AppSettings["UploadTmp"] + article.ImgFileList[i].ImgFileName; // string fileExtension = Path.GetExtension(fromPath); // 文件扩展名 // string categoryFix = "other"; // //根据文件类别+分类下序数命名新图片名 // var firstKey = Constants.ChannelToCategory.FirstOrDefault(q => q.Value == article.CategoryId.Value).Key; // if (!string.IsNullOrEmpty(firstKey)) // { // categoryFix = firstKey; // } // string newFileName = categoryFix + article.NoOfCategory.ToString().PadLeft(2, '0') + "_" + j + fileExtension; // 文件扩展名 //jt01_1.jpg // ++j; // string toPath = savePath + ConfigurationManager.AppSettings["AriticleImagePath"] + newFileName; // if (!Directory.Exists(savePath + ConfigurationManager.AppSettings["AriticleImagePath"])) // { // Directory.CreateDirectory(savePath + ConfigurationManager.AppSettings["AriticleImagePath"]); // } // System.IO.File.Copy(fromPath, toPath); // //TODO Insert ArticleImage // ArticleImageEntity articleImage = new ArticleImageEntity(); // articleImage.ArticleId = article.Id; // articleImage.ImageFileName = newFileName; // articleImageBLL.AddArticleImageEntity(articleImage); // } //} return(JsonConvert.SerializeObject(new { result = true, message = "", returnUrl = "/Admin/Article/Index?JournalId=" + article.JournalId })); } return(JsonConvert.SerializeObject(new { result = false, message = "" })); }