public IActionResult Add(int?id) { ViewBag.BlogTypes = _sysConfig.GetConfigList(SysConfig.BlogType); ViewBag.CategList = _categService.GetList(""); T_BLOG_CONTENT content = new T_BLOG_CONTENT(); if (id != null) { content = _contentService.GetModel(" b.BlogID=" + id.Value); } return(View(content)); }
public int Insert(T_BLOG_CONTENT model, IDbTransaction transaction) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_BLOG_CONTENT("); strSql.Append("BlogTitle,BlogCover,BlogContent,BlogType,BlogState,LastUptTime,CreateUser,CreateTIme,UpdateUser,UpdateTIme,Remark)"); strSql.Append(" values ("); strSql.Append("@BlogTitle,@BlogCover,@BlogContent,@BlogType,@BlogState,@LastUptTime,@CreateUser,@CreateTIme,@UpdateUser,@UpdateTIme,@Remark)"); strSql.Append("; SELECT @@IDENTITY ;"); using (var conn = ConnentionFactory.GetOpenSqlConnection(ConnStr)) { int contentBlogID = conn.Query <int>(strSql.ToString(), model, transaction).First(); return(contentBlogID); } }
public IActionResult Add(T_BLOG_CONTENT content) { try { //if (!ModelState.IsValid) // return Content("<script> alert('博客内容有误,请检查博客内容!'); location.href='/Admin/Blog/Add'</script>", "text/html"); int blogId = 0; //int userId = HttpContext.Session.GetInt32("userid") == null // ? 1 // : int.Parse(HttpContext.Session.GetInt32("userid").ToString()); int userId = int.Parse(User.Identities.First(u => u.IsAuthenticated) .FindFirst(ClaimTypes.PrimarySid).Value); if (content.BlogID == 0) { content.CreateTIme = DateTime.Now; content.CreateUser = userId; content.LastUptTime = DateTime.Now; content.BlogState = 1; blogId = _contentService.Insert(content); } else { blogId = content.BlogID; content.UpdateUser = userId; content.LastUptTime = DateTime.Now; content.BlogState = 1; bool isSuccess = _contentService.Update(content); if (isSuccess) { _relCateg.Delete(content.BlogID); } } if (blogId > 0) { _relCateg.Insert(blogId, content.CatelogID); } return(Redirect("/Admin/Blog/Index")); } catch (Exception ex) { _logger.LogError(ex.Message); return(null); } }
/// <summary> /// 修改博客内容 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Update(T_BLOG_CONTENT model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_BLOG_CONTENT set "); strSql.Append("BlogTitle=@BlogTitle,"); strSql.Append("BlogCover=@BlogCover,"); strSql.Append("BlogContent=@BlogContent,"); strSql.Append("BlogType=@BlogType,"); strSql.Append("BlogState=@BlogState,"); strSql.Append("LastUptTime=@LastUptTime,"); strSql.Append("UpdateUser=@UpdateUser,"); strSql.Append("UpdateTIme=@UpdateTIme,"); strSql.Append("Remark=@Remark"); strSql.Append(" where BlogID=@BlogID"); using (var conn = ConnentionFactory.GetOpenSqlConnection(ConnStr)) { int resBlogID = conn.Execute(strSql.ToString(), model); return(resBlogID > 0); } }