public ActionResult AddBlog(AddBlogViewModel addBlogViewModel) { Response response = new Response() { Code = 0 }; Blog blog; if (ModelState.IsValid) { var category = categoryManager.Find(addBlogViewModel.CategoryId); if (category == null || category.Type != CategoryType.General) { response.Message = "栏目不匹配或者未找到!"; return(Json(response)); } if (blogManager.Find(b => b.Title == addBlogViewModel.Title) != null) { response.Message = "标题重复了!"; return(Json(response)); } blog = Mapper.Map <Blog>(addBlogViewModel); blog.Category = category; response = blogManager.AddBlog(blog); } else { response.Message = "输入不合法!"; } return(Json(response)); }
// // GET: /Member/Content/ public ActionResult Index(int id) { #region 网站设置 CustomCon custom = (CustomCon)ConfigurationManager.GetSection("customCon"); WebInfo webInfo = custom.WebInfo; ViewBag.WebInfo = webInfo; #endregion Blog blog = blogManager.Find(id); if (blog == null) { return(View("Prompt", new Prompt() { Title = "错误", Message = "该文章不存在!" })); } if (!blog.Publish) { return(View("Prompt", new Prompt() { Title = "错误", Message = "该文章未发布!" })); } blog.Volume = blog.Volume + 1; blogManager.Update(blog); return(View(blog)); }
public ActionResult Index(int?pageindex, int id = -1) { Paging <Blog> page = new Paging <Blog>(); page.PageIndex = pageindex == null ? 1 : pageindex.Value; page.PageSize = 5; page.Items = blogManager.Getlist(page, id).ToList(); #region 构造分页 //构造标签 int PageCount = page.TotalNumber; int PageSize = page.PageSize; int totalPage = (PageCount + PageSize - 1) / PageSize; string urlhead = "/Member/Home/Index/" + id + "?pageindex="; string pages = "<li><a href='" + urlhead + "1" + "'>首页</a></li>";; if (page.PageIndex == 1) { pages += "<li class='disabled'><a href='#'>上一页</a></li>"; } else { pages += "<li ><a href='" + urlhead + (page.PageIndex - 1) + "'>上一页</a></li>"; } if (page.PageIndex == totalPage) { pages += "<li class='disabled'><a href='#'>下一页</a></li>"; } else { pages += "<li ><a href='" + urlhead + (page.PageIndex + 1) + "'>下一页</a></li>"; } pages += "<li ><a href='" + urlhead + totalPage + "'>最后一页</a></li>"; ViewBag.Page = pages; ViewBag.PageIndex = page.PageIndex; ViewBag.PageCount = totalPage; #endregion #region 网站设置 //CustomCon custom = (CustomCon)ConfigurationManager.GetSection("customCon"); //WebInfo webInfo = custom.WebInfo; ViewBag.WebInfo = webInfo; #endregion #region 置顶博客 var TopBlog = blogManager.Find(webConfigManager.GetConfig().TopBlog); ViewBag.TopBlog = TopBlog; #endregion return(View(page.Items)); }
public ActionResult TopBlog(int id) { Response response = new Response() { Code = 0 }; if (blogManager.Find(id) == null) { response.Message = "该博客不存在!"; return(Json(response)); } webConfigManager.SetConfig("TopBlog", id.ToString()); response.Code = 1; return(Json(response)); }