public IActionResult Edit(string ArticleKey) { VM_Article article = new VM_Article(); if (string.IsNullOrEmpty(ArticleKey)) { article.ArticleKey = "A_" + Guid.NewGuid().ToString().Replace("-", ""); article.IsPublish = false; article.CanUploadOrPublish = false; article.ArticleTag = string.Empty; article.ArticleCategory = string.Empty; } else { var entity = _PubComService._Pri_ArticleDraft_DataService.GetPri_ArticleDraft(ArticleKey); if (entity == null) { return(RedirectToAction("Index")); } article.ArticleKey = ArticleKey; article.ArticleTitle = entity.ArticleTitle; article.ArticleCategory = entity.ArticleCategory; article.ContentText = entity.ContentText; article.ArticleTag = entity.ArticleTag; article.ArticleDesc = entity.ArticleDesc; article.AidStyle = entity.AidStyle; article.IsPublish = _PubComService._Pub_Article_DataService.GetPub_Article_Entity(ArticleKey) != null; article.CanUploadOrPublish = entity != null; } article.ArticlePreviewUrl = _PubComService._OctOceanConfig.ArticlePreviewUrl + "/" + ArticleKey + "?t=p"; article.Base_ArticleCategoryddl = new SelectList(_PubComService._Base_ArticleCategoryService.GetAllArticleCategory(), "ArticleCategoryCode", "ArticleCategoryName", ""); //默认选择空值 article.Base_ArticleTagList = _PubComService._Base_ArticleTag_DataService.GetAllArticleTag(); var allimagelist = _PubComService._Pri_ArticleImage_DataService.GetAllPri_ArticleImage(ArticleKey); if (allimagelist != null) { article.Pri_ArticleImageList = allimagelist.OrderBy(a => a.UpdateTime).ToList(); } return(View(article)); }
public IActionResult Submit([Bind("ArticleKey,ArticleTitle,ArticleCategory,ContentText,ArticleTag,ArticleDesc,AidStyle")] VM_Article article) { if (ModelState.IsValid) { if (article.ContentText != null) { var _cont = article.ContentText.Replace("<p>", "").Replace("<br>", "").Replace("</p>", "").Replace("</br>", ""); //去掉自带的样式 if (string.IsNullOrWhiteSpace(_cont)) { article.ContentText = ""; } } if (string.IsNullOrWhiteSpace(article.ArticleTitle) && string.IsNullOrWhiteSpace(article.ContentText) && string.IsNullOrWhiteSpace(article.ArticleDesc) && string.IsNullOrWhiteSpace(article.AidStyle)) { return(RedirectToAction("Edit", new { ArticleKey = article.ArticleKey })); } article.ContentText = _PubComService._Pri_ArticleImage_DataService.ReplaceImagesPlaceholder(article.ContentText, article.ArticleKey); //将数据存入到Temp中去 var tempdal = _PubComService._Pri_ArticleDraft_Temp_DataService; var draftdal = _PubComService._Pri_ArticleDraft_DataService; //只要有新的内容,就存成草稿状态 int oi = tempdal.InsertPri_ArticleDraft_Temp(new Pri_ArticleDraft_Temp_Entity() { ArticleKey = article.ArticleKey, ArticleTag = article.ArticleTag ?? "", ArticleDesc = article.ArticleDesc ?? "", AidStyle = article.AidStyle ?? "", ArticleCategory = article.ArticleCategory ?? "", ArticleTitle = article.ArticleTitle ?? "", ContentText = article.ContentText ?? "", UpdateTime = DateTime.Now }); var submitData = new Pri_ArticleDraft_Entity() { ArticleKey = article.ArticleKey, ArticleTag = article.ArticleTag ?? "", ArticleDesc = article.ArticleDesc ?? "", AidStyle = article.AidStyle ?? "", ArticleCategory = article.ArticleCategory ?? "", ArticleTitle = article.ArticleTitle ?? "", ContentText = article.ContentText ?? "", UpdateTime = DateTime.Now }; var olddraft = draftdal.GetPri_ArticleDraft(article.ArticleKey); if (olddraft == null) { //插入操作 draftdal.InsertPri_ArticleDraft(submitData); } else { //必须在Draft中有这条记录修改才能生效,也就是说,只有点了保存按钮,产生了数据,才能够和temp数据进行关联,这样的话可以减少草稿内容(比如测试、或者打开页面没有做任何事情)的产生。 draftdal.UpdatePri_ArticleDraft(submitData); } } return(RedirectToAction("Edit", new { ArticleKey = article.ArticleKey })); }