public ActionResult Add(string Name, string Introduction) { AjaxResponse<object> obj = new AjaxResponse<object>(); if (string.IsNullOrEmpty(Name)) { obj.ErrorMessage = "分类名称不能为空"; return Json(obj); } if (Name.Length > 15) { obj.ErrorMessage = "分类名称不能超过15个字"; return Json(obj); } //保证Name唯一,先查询一下是不是有这个Name var temp = ArticleTypeService.PageLoad(a => a.Name == Name).FirstOrDefault(); if (temp != null) { obj.ErrorMessage = "该分类已经存在!"; return Json(obj); } ArticleType articleType = new ArticleType { Name = Name, Status = StatusEnum.Normal }; obj.IsSuccess = ArticleTypeService.AddModel(articleType); return Json(obj); }
public ActionResult Add(string Name, int? Pid = 0) { AjaxResponse<ArticleType> obj = new AjaxResponse<ArticleType>(); if (string.IsNullOrEmpty(Name)) { obj.ErrorMessage = "分类名称不能为空"; return Json(obj); } if (Name.Length > 20) { obj.ErrorMessage = "分类名称不能超过20个字"; return Json(obj); } #region 先注释掉,不同分类下其实是有子分类名字一样的 ////保证Name唯一,先查询一下是不是有这个Name //var temp = ArticleTypeService.PageLoad(a => a.Name == Name).FirstOrDefault(); //if (temp != null) //{ // obj.ErrorMessage = "该分类已经存在!"; // return Json(obj); //} #endregion ArticleType articleType = new ArticleType { Name = Name, Pid = Pid == 0 ? null : Pid, Status = StatusEnum.Normal }; obj.IsSuccess = ArticleTypeService.AddModel(articleType); return Json(obj); }
public JsonResult Update(string Name, int? Pid, int Status, int Id = 0) { AjaxResponse<ArticleType> obj = new AjaxResponse<ArticleType>(); if (string.IsNullOrEmpty(Name)) { obj.ErrorMessage = "分类名称不能为空"; return Json(obj); } if (Name.Length > 15) { obj.ErrorMessage = "分类名称不能超过15个字"; return Json(obj); } if (Id == Pid) { obj.ErrorMessage = "分类并没有变化"; return Json(obj); } ArticleType articleType = new ArticleType { Id = Id, Name = Name, Pid = Pid == 0 ? null : Pid, Status = Status != 99 ? StatusEnum.Normal : StatusEnum.Delete }; obj.IsSuccess = ArticleTypeService.UpdateModel(articleType); return Json(obj); }