public ActionResult CreateCategory(CreateCategoryViewModel model) { if (ModelState.IsValid) { IBLL.IArticleManager articleManager = new ArticleManager(); articleManager.CreateCategory(model.CategoryName, Guid.Parse(Session["userid"].ToString())); return(RedirectToAction("CategoryList")); } ModelState.AddModelError("", "您录入的信息有误"); return(View(model)); }
public ActionResult CreateCategory(CreateCategory model) { if (ModelState.IsValid) { BlogSystem.IBLL.IArticleManager articleManager = new ArticleManager(); articleManager.CreateCategory(model.CategoryName, Guid.Parse(Session["userId"].ToString())); return(RedirectToAction("CategoryList")); } ModelState.AddModelError(key: "", errorMessage: "您的信息有误!"); return(View(model)); }
public async Task <ActionResult> CreateCategory(CategoryViewModels category) { if (ModelState.IsValid) { IArticleManager articleManager = new ArticleManager(); await articleManager.CreateCategory(category.CategoryName, Guid.Parse(Session["userId"].ToString())); return(RedirectToAction("categoryList", "Article")); } ModelState.AddModelError("categoryError", "您的输入有误,请重新输入"); return(View(category)); }
public async Task <ActionResult> AddCategory(string categoryName) { //不可为空,不可重复,未登录无法提交 if (categoryName == null || categoryName.Trim() == "") { return(Json(new { status = "fail", result = "分类名称不可为空!" }, JsonRequestBehavior.AllowGet)); } //获取当前登陆的id,cookie的id需要解密 string userCookieId = ""; string message; if (Request.Cookies["userId"] != null) { if (!JwtHelper.GetJwtDecode(Request.Cookies["userId"].Value, out userCookieId, out message)) { return(Json(new { status = "fail", result = message }, JsonRequestBehavior.AllowGet)); } } string userId = Session["userId"] == null ? userCookieId : Session["userId"].ToString(); //优先获取session的id if (userId == "") //未登录提醒 { return(Json(new { status = "fail", result = "未登陆无法提交!" }, JsonRequestBehavior.AllowGet)); } IArticleManager articleManager = new ArticleManager(); List <BlogCategoryDto> categoryList = await articleManager.GetAllCategories(Guid.Parse(userId));//获取所有分类名,循环对比是否有重复 bool isRepeat = false; foreach (var cate in categoryList) { if (cate.BlogCategoryName == categoryName) { isRepeat = true; break; } } if (isRepeat) { return(Json(new { status = "fail", result = "添加的分类名称已存在,请勿重复添加!" }, JsonRequestBehavior.AllowGet)); } await articleManager.CreateCategory(categoryName, Guid.Parse(userId));//添加分类 return(Json(new { status = "ok", result = "添加成功!" }, JsonRequestBehavior.AllowGet)); }