/// <summary> /// 名称:添加个人类别视图 /// 时间:18-1-19 /// 作者:赵文涵 /// </summary> /// <returns></returns> public ActionResult AddCategory() { //严重登陆信息 IsLogin(); //int rows; ////如果为""就赋值为1 //if (Request["num"] == "") //{ // rows = 1; //} ////如果为null就赋值为1 //rows = Convert.ToInt32(Request["num"] ?? "1"); //获取当前登陆用户的session int _loginId = (Session["ULogin"] as ULogin).ULogin_Id; //查询全部 List <Category> lis = DTO_Category.SelectCategory(_loginId).ToList(); ////分页后的条数 //List<Category> lis = lis2.Skip((rows - 1) * 5).Take(5).ToList(); ////得到所有条数 //int allcount = lis2.Count(); ////得到所有页数 //int allpage = allcount / 5; ////判断是否除尽或页数是否为0 //if (allcount % 5 != 0 || allpage == 0) // allpage += 1; return(View(lis)); }
public JsonResult SearchCategory(string _val) { IsLogin(); //获取用户登录账号编号 var _ulogin = Session["ULogin"] as ULogin; return(Json(DTO_Category.SelectCategory(_ulogin.ULogin_Id, _val), JsonRequestBehavior.AllowGet)); //SelectCategory }
public ActionResult WriteBlogIndex() { ULogin u = new ULogin() { ULogin_Id = 1 }; //Session["ULogin"] as ULogin; //查询所有的后台博客类别 List <Backstage_Category> _bclist = DTO_Backstage_Category.SelectBackstage_Category(); //查询所有自定类别 List <Category> clist = DTO_Category.SelectCategory(u.ULogin_Id); @ViewBag._bclist = _bclist; @ViewBag.clist = clist; return(View()); }
public ActionResult UpdateWriteBlogIndex(int Write_blog_Id) { ULogin u = Session["ULogin"] as ULogin;//Session["ULogin"] as ULogin; MonkeyDBEntities db = new MonkeyDBEntities(); //查询所有的后台博客类别 List <Backstage_Category> _bclist = DTO_Backstage_Category.SelectBackstage_Category(); //查询所有自定类别 List <Category> clist = DTO_Category.SelectCategory(u.ULogin_Id); Write_blog wb = db.Write_blog.Where(a => a.Write_blog_Id == Write_blog_Id).FirstOrDefault(); string[] strlist = wb.Category_Id.Split(',');//这篇文章的类型数组 @ViewBag._bclist = _bclist; @ViewBag.clist = clist; @ViewBag.wb = wb; @ViewBag.Mycalist = strlist; return(View()); }
// // GET: /PersonalBlog/ /// <summary> /// 个人博客页面 /// </summary> /// <param name="searchcontent"></param> /// <returns></returns> public ActionResult PersonalBlogIndex(string searchcontent) { MonkeyDBEntities db = new MonkeyDBEntities(); int rows; //如果为""就赋值为1 if (Request["num"] == "") { rows = 1; } //如果为null就赋值为1 rows = Convert.ToInt32(Request["num"] ?? "1"); int Write_ArticleType; if (Request["Write_ArticleType"] == "") { Write_ArticleType = -1; } Write_ArticleType = Convert.ToInt32(Request["Write_ArticleType"] ?? "-1"); ULogin ul2 = Session["ULogin"] as ULogin;//查看人的人id ULogin ul = new ULogin { ULogin_Id = 1 }; //该博客的id //创建一个返回值为bool型的委托 Func <Write_blog, bool> getpage = a => a.Write_IsDel == 2 && a.Write_State == 2 && a.ULogin_IdIsManager == "否" && (Write_ArticleType == -1 || a.Write_ArticleType == Write_ArticleType) && (string.IsNullOrEmpty(searchcontent) || a.Write_Content.Contains(searchcontent.Trim()) || a.Write_Title.Contains(searchcontent.Trim()) || a.Write_Label.Contains(searchcontent.Trim())); //创建以及博客集合 List <Write_blog> wblist = new List <Write_blog>(); //查询博主的所有文章 List <Write_blog> allwblist = db.Write_blog.AsNoTracking().Where(a => a.ULogin_Id == ul.ULogin_Id).ToList(); //判断是否为本人看的 if (ul2 == null || ul.ULogin_Id != ul2.ULogin_Id) { //不是本人查看时(不能查看私有的博客) //getpage = a => a.Write_IsDel == 2 && a.Write_State == 2 && a.Write_Private == 1 && (Write_ArticleType == -1 || a.Write_ArticleType == Write_ArticleType) && (string.IsNullOrEmpty(searchcontent.Trim()) || a.Write_Content.Contains(searchcontent) || a.Write_Title.Contains(searchcontent.Trim()) || a.Write_Label.Contains(searchcontent.Trim())); wblist = allwblist.Where(getpage).Where(a => a.Write_Private == 1).OrderByDescending(a => a.Write_blog_Id).Skip((rows - 1) * 5).Take(5).ToList(); } else { //本人查看时 wblist = allwblist.Where(getpage).OrderByDescending(a => a.Write_blog_Id).Skip((rows - 1) * 5).Take(5).ToList(); } //创建一个装评论条数的集合 List <int> bccountlist = new List <int>(); //查询所有的评论 List <Blog_Comment> bclist = db.Blog_Comment.AsNoTracking().ToList(); //遍历博客 foreach (var item in wblist) { //查询该博客对应的评论的条数 int count = bclist.Where(a => a.BC_ArticleID == item.Write_blog_Id).Count(); //添加到集合 bccountlist.Add(count); } //得到所有条数 int allcount = db.Write_blog.Where(getpage).ToList().Count(); //得到所有页数 int allpage = allcount / 5; //判断是否除尽或页数是否为0 if (allcount % 5 != 0 || allpage == 0) { allpage = allpage + 1; } //查询所有的个人分类 List <Category> calist = DTO_Category.SelectCategory(ul.ULogin_Id); //查询所有的博客里面的分类 List <string> caidlist = allwblist.Select(a => a.Category_Id).ToList(); //定义以个人分类编号作为键,个人分类下面的博客数作为值的数组 // int[] cateidcount = new int[calist.Count()]; Dictionary <int, int> dic_cateidcount = new Dictionary <int, int>(); //定义一个装所有博客文章里面个人分类的集合 List <int> listid = new List <int>(); //遍历所有的博客里面的分类 foreach (var item in caidlist) { //分割字符串 string[] id = item.Split(','); //遍历数组 for (int i = 0; i < id.Length; i++) { //添加到集合 listid.Add(Convert.ToInt32(id[i])); } } //遍历个人分类 foreach (var item in calist) { //根据跟人分类的编号查询博客的文章数 int count2 = listid.Where(a => a == item.Category_Id).Count(); //以键值对的形式添加到集合 dic_cateidcount[item.Category_Id] = count2; } //传值到页面 ViewBag.allpage = allpage; ViewBag.rows = rows; ViewBag.bccountlist = bccountlist; ViewBag.wblist = wblist; ViewBag.searchcontent = searchcontent; ViewBag.Write_ArticleType = Write_ArticleType; ViewBag.cateidcount = dic_cateidcount; ViewBag.calist = calist; ViewBag.LoginUser = ul2; //登陆的账号 ViewBag.WatchUser = ul; //看博客的账号 return(View()); }