public ActionResult AddNews() { if (!AppData.IsManagerLogin) { return(Json(new { success = false, msg = "您未登录后台或会话已过期" })); } if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 201)) { return(Json(new { success = false, msg = "您没有执行该操作的权限" })); } Validation validation = new Validation(); NewsObj newsObj = new NewsObj(); newsObj.CategoryID = validation.GetInt("categoryID"); newsObj.Title = validation.Get("title", false, "请填写新闻标题"); newsObj.Writer = validation.Get("writer"); newsObj.Tags = validation.Get("tags"); newsObj.PublishDate = DateTime.Now; newsObj.Content = HttpUtility.UrlDecode(validation.Get("content", false, "请填写新闻内容"), Encoding.UTF8); if (validation.HasError || newsObj.CategoryID == 0) { return(Json(new { success = false, msg = "参数错误", errors = validation.GetErrors() })); } newsObj.Sort = DateTime.Now; newsObj.Clicks = 0; NewsBLL newsBLL = new NewsBLL(); newsBLL.AddNews(newsObj); if (newsObj.NewsID != 0) { return(Json(new { success = true, id = newsObj.NewsID })); } else { return(Json(new { success = false, msg = "抱歉,添加失败!" })); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; if (context.Session["id"] != null) { string title = context.Request.Form["title"]; string type = context.Request.Form["type"]; string content = context.Request.Form["content"]; string adminName = AdminBLL.GetNameById(Convert.ToInt32(context.Session["id"])); NewsModel news = new NewsModel(0, title, content, DateTime.Now, 0, "", Convert.ToInt32(type), adminName); int i = NewsBLL.AddNews(news); if (i > 0) { context.Response.Write("新闻添加成功<a href='ProcessAdminNews.ashx'>回到新闻首页</a>"); } } else { context.Response.Redirect("~/admin_login.html"); } }