public ActionResult Add(string SeoKeywords, string Sedescription) { AjaxResponse<SeoTKD> obj = new AjaxResponse<SeoTKD>(); if (string.IsNullOrEmpty(SeoKeywords)) { obj.ErrorMessage = "关键字不能为空"; return Json(obj); } if (SeoKeywords.Length > 149) { obj.ErrorMessage = "关键字不能超过149个字"; return Json(obj); } if (string.IsNullOrEmpty(Sedescription)) { obj.ErrorMessage = "描述不能为空"; return Json(obj); } if (Sedescription.Length > 249) { obj.ErrorMessage = "描述不能超过249个字"; return Json(obj); } SeoTKD SeoTKD = new SeoTKD { SeoKeywords = SeoKeywords, Sedescription = Sedescription, Status = StatusEnum.Normal }; obj.IsSuccess = SeoTKDService.AddModel(SeoTKD); return Json(obj); }
public JsonResult Update(string SeoKeywords, string Sedescription, int Status, int Id = 0) { AjaxResponse<SeoTKD> obj = new AjaxResponse<SeoTKD>(); if (string.IsNullOrEmpty(SeoKeywords)) { obj.ErrorMessage = "关键字不能为空"; return Json(obj); } if (SeoKeywords.Length > 149) { obj.ErrorMessage = "关键字不能超过149个字"; return Json(obj); } if (string.IsNullOrEmpty(Sedescription)) { obj.ErrorMessage = "描述不能为空"; return Json(obj); } if (Sedescription.Length > 249) { obj.ErrorMessage = "描述不能超过249个字"; return Json(obj); } SeoTKD SeoTKD = new SeoTKD { Id = Id, SeoKeywords = SeoKeywords, Sedescription = Sedescription, Status = Status != 99 ? StatusEnum.Normal : StatusEnum.Delete }; obj.IsSuccess = SeoTKDService.UpdateModel(SeoTKD); return Json(obj); }
public JsonResult Update(int ArticleId = 0, int SeoId = 0, string CreateTime = "", string Title = "", string Author = "", string TContent = "", string TypeIds = "", string TagIds = "", int GroupType = 1, int Recommend = 0, int HitCount = 9, int Sort = 9, int Status = 0, string DisplayPic = "", string SeoKeywords = "", string Seodescription = "") { AjaxResponse<object> obj = new AjaxResponse<object>(); #region 一系列验证 if (ArticleId == 0 || SeoId == 0) { obj.ErrorMessage = "文章或Seo不存在!"; return Json(obj); } if (string.IsNullOrEmpty(Title)) { obj.ErrorMessage = "文章标题不能为空!"; return Json(obj); } if (string.IsNullOrEmpty(Author)) { obj.ErrorMessage = "作者不能为空!"; return Json(obj); } if (string.IsNullOrEmpty(TContent)) { obj.ErrorMessage = "文章内容不能为空!"; return Json(obj); } if (string.IsNullOrEmpty(TypeIds)) { obj.ErrorMessage = "请好好选择文章分类!"; return Json(obj); } if (string.IsNullOrEmpty(TagIds)) { obj.ErrorMessage = "请好好选择文章Tag!"; return Json(obj); } if (string.IsNullOrEmpty(SeoKeywords)) { obj.ErrorMessage = "Seo关键词不能为空!"; return Json(obj); } if (string.IsNullOrEmpty(Seodescription)) { obj.ErrorMessage = "Seo头部描述能为空!"; return Json(obj); } if (Title.Length > 50) { obj.ErrorMessage = "新闻标题50个字以内!"; return Json(obj); } if (Author.Length > 15) { obj.ErrorMessage = "作者15个字以内!"; return Json(obj); } if (SeoKeywords.Length > 149) { obj.ErrorMessage = "Seo头关键词149字以内!"; return Json(obj); } if (Seodescription.Length > 249) { obj.ErrorMessage = "Seo头部描述249字以内!"; return Json(obj); } if (TagIds.Length > 100) { obj.ErrorMessage = "文章Tag好像有点太多了啊!"; return Json(obj); } if (TypeIds.Length > 100) { obj.ErrorMessage = "文章分类好像有点那个啥吧!"; return Json(obj); } #endregion SeoTKD seoInfo = new SeoTKD() { Id = SeoId, SeoKeywords = SeoKeywords, Sedescription = Seodescription, Status = StatusEnum.Normal }; #region 存储前的处理 TypeIds = TypeIds.Trim(','); TagIds = TagIds.Trim(','); DateTime timeTemp; DateTime.TryParse(CreateTime, out timeTemp); //传过来的已经url编码了【带敏感字符的url服务器默认是拒绝请求的】 //没有url编码的,解码还是他本身 TContent = HttpUtility.UrlDecode(TContent); //必须保证存在数据库里面的文字是安全的 TContent = HttpUtility.HtmlEncode(TContent); //如果没有上传默认展图,就随机展示一个默认展图 if (string.IsNullOrEmpty(DisplayPic)) { IList<ArticleDisPhoto> disPics = ArticleDisPhotoService.PageLoad(p => p.Status != StatusEnum.Delete).ToList(); int count = disPics.Count; if (count > 0) { Random random = new Random(); int index = random.Next(disPics.Count); DisplayPic = disPics[index].PicUrl; } else//实在没有的话就给一个默认值 { DisplayPic = LoT.Common.ConfigHelper.GetValueForConfigAppKey("ArticleTypeDisPlayPic"); } } #endregion Article article = new Article() { Id = ArticleId, Title = Title, Author = Author, TContent = TContent, CreateTime = timeTemp, UpdateTime = DateTime.Now, TypeIds = TypeIds, GroupType = (GroupEnum)(GroupType == 0 ? 1 : GroupType), Recommend = (RecommendEnum)Recommend, HitCount = HitCount, Sort = Sort, TagIds = TagIds, Status = (ArticleStatusEnum)Status, DisplayPic = DisplayPic, SeoId = SeoId }; bool b = ArticleService.UpdateArticle(article, seoInfo) > 0; obj.IsSuccess = b; if (!b) { obj.ErrorMessage = "未知原因添加失败~"; } return Json(obj); }