Example #1
0
        public ActionResult user()
        {
            var Id = Request["Id"].ToInt();

            using (var db = new ClubEntities())
            {
                var loginUser = (User)Session["loginUser"];
                ViewBag.LoginUser = loginUser;
                var postList = new List <ListPostModel>();
                var list     = db.Post.ToList();
                foreach (var item in list)
                {
                    var postModel = new ListPostModel();
                    postModel.Id         = item.Id;
                    postModel.Title      = item.Title;
                    postModel.UserName   = item.User.Name;
                    postModel.CreateTime = item.CreateTime;
                    postModel.ViewCount  = item.ViewCount;
                    postModel.Status     = item.Status.ToString();
                    postModel.UserImage  = item.User.Image;
                    postList.Add(postModel);
                }
                return(View(postList));
            }
        }
Example #2
0
        public ActionResult Category4()
        {
            var loginUser = (User)Session["loginUser"];

            ViewBag.LoginUser = loginUser;
            int pageSize  = 5;
            var pageIndex = Request["pageIndex"].ToInt(1);
            var kw        = Request["kw"];
            IPagedList <Club.Models.ListPostModel> pt;
            var cookies = new HttpCookie("User");

            using (var db = new ClubEntities())
            {
                var postList = new List <ListPostModel>();
                var list     = db.Post.OrderByDescending(a => a.Id).Include(a => a.User).Include(a => a.Category).Where(a => a.CategoryId == 4).ToList();
                var category = db.Category.Where(a => a.IsAbort == false).ToList();
                ViewBag.category = category;
                foreach (var item in list)
                {
                    var postModel = new ListPostModel();
                    postModel.Id         = item.Id;
                    postModel.Title      = item.Title;
                    postModel.UserName   = item.User.Name;
                    postModel.CreateTime = item.CreateTime;
                    postModel.ViewCount  = item.ViewCount;
                    postModel.PostReply  = item.ReplyCount;
                    if (item.Status == 1)
                    {
                        postModel.Status = "【精】";
                    }
                    else
                    {
                        postModel.Status = "";
                    }
                    postModel.UserImage = item.User.Image;
                    postList.Add(postModel);
                }
                pt = postList.OrderByDescending(a => a.CreateTime).ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                return(View(pt));
            }
        }
Example #3
0
        public ActionResult Index()
        {
            #region 数据库的增删改查
            //using (var db = new ClubEntities())
            //{
            //    var level = new Level();
            //    level.Name = "级别1";

            //    db.Level.Add(level);
            //    db.SaveChanges();
            //}


            //using (var db = new ClubEntities())
            //{
            //    for (int i = 0; i < 100; i++)
            //    {
            //        var user = new User();
            //        user.LevelId = 1;
            //        user.Name = "张" + i;
            //        user.Account = "张" + i;
            //        user.PassWord = "******";
            //        db.User.Add(user);
            //        db.SaveChanges();
            //    }

            //}

            //using (var db= new ClubEntities())
            //{
            //    var user = db.User.FirstOrDefault(a => a.Id == 2);
            //    if (user != null)
            //    {
            //        db.User.Remove(user);
            //        db.SaveChanges();
            //    }

            //}

            //using (var db=new ClubEntities())
            //{

            //    var user = db.User.FirstOrDefault(a => a.Id == 3);
            //    if (user != null)
            //    {
            //        user.Name = "软件153的用户";
            //    }
            //    db.SaveChanges();
            //}

            //using (var db=new ClubEntities())
            //{

            //    var users = db.User.Where(t => t.Id < 10).ToList();

            //    var sb=new StringBuilder();
            //    foreach (var item in users)
            //    {
            //        sb.AppendLine("用户名:" + item.Name+"用户级别:"+item.Level.Name);
            //    }
            //    return Content(sb.ToString());

            //}



            //密码加密
            //using (var db = new ClubEntities())
            //{
            //    var users = db.User.ToList();
            //    foreach (var user in users)
            //    {
            //        //var pw = EncryptHelper.MD5Encoding(user.PassWord, user.Account);
            //        user.PassWord = user.PassWord.MD5Encoding(user.Account);
            //    }
            //    db.SaveChanges();
            //}
            // var pw = EncryptHelper.MD5Encoding("000000","zhangchi");
            //return Content("ok");
            #endregion

            //最新发表
            var loginUser = (User)Session["loginUser"];
            ViewBag.LoginUser = loginUser;
            int pageSize  = 5;
            var pageIndex = Request["pageIndex"].ToInt(1);
            var kw        = Request["kw"];
            IPagedList <Club.Models.ListPostModel> pt;
            var cookies = new HttpCookie("User");
            using (var db = new ClubEntities())
            {
                var postList = new List <ListPostModel>();
                var list     = db.Post.OrderByDescending(a => a.Id).Include(a => a.User).Include(a => a.Category).Where(a => a.IsFeatured == true).ToList();
                var category = db.Category.Where(a => a.IsAbort == false).ToList();
                ViewBag.category = category;
                foreach (var item in list)
                {
                    var postModel = new ListPostModel();
                    postModel.Id         = item.Id;
                    postModel.Title      = item.Title;
                    postModel.UserName   = item.User.Name;
                    postModel.CreateTime = item.CreateTime;
                    postModel.ViewCount  = item.ViewCount;
                    postModel.PostReply  = item.ReplyCount;
                    if (item.Status == 1)
                    {
                        postModel.Status = "【精】";
                    }
                    else
                    {
                        postModel.Status = "";
                    }
                    postModel.UserImage = item.User.Image;
                    postList.Add(postModel);
                }
                pt = postList.OrderByDescending(a => a.CreateTime).ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                return(View(pt));
            }
        }
Example #4
0
        /// <summary>
        /// 帖子列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        // GET: Post
        public ActionResult Index(int?id)
        {
            var pageIndex = id ?? 1;
            int pageSize  = 6;
            //自定义
            //      key==1 为搜索
            //      key==2 为帖子最新发布和回复选择
            //      key==3 为帖子类型选择
            var key      = Request["key"].ToInt();
            var value    = Request["value"];
            var listpost = new List <ListPostModel>();

            using (var db = new ClubEntitie())
            {
                var type = db.Type.ToList();
                ViewBag.type = type;
                //会员数量
                var user = db.User.Where(a => a.Levelid == 2).ToList();
                ViewBag.MemberNumber = user.Count();
                //帖子数量
                var post = db.Post.ToList();
                ViewBag.PostNumber = post.Count();
                //精品数量
                post = post.Where(a => a.Essence == 1).ToList();
                ViewBag.BoutiqueNumber = post.Count();
                post = db.Post.OrderByDescending(a => a.Recoverytime).Include(a => a.User).Include(a => a.Type).Where(a => a.IsFeatured == true).ToList();
                var reply = new List <Reply>();
                //按帖子类型查找
                switch (key)
                {
                case 1:
                    post = post.Where(a => a.Title.Contains(value) || a.User.Name.Contains(value)).ToList();
                    break;

                case 2:
                    var tabid = value.ToInt();
                    switch (tabid)
                    {
                    case 2:
                        post = post.OrderByDescending(a => a.Time).ToList();
                        break;

                    case 3:
                        post = post.Where(a => a.Essence == 1).ToList();
                        break;
                    }
                    break;

                case 3:
                    var typeid = value.ToInt();
                    //typeid==0  全部帖子
                    if (typeid > 0)
                    {
                        post = post.Where(a => a.Typeid == typeid).ToList();
                    }
                    break;
                }
                foreach (var item in post)
                {
                    var postModel = new ListPostModel();
                    var postreply = db.Reply.Where(a => a.Postid == item.id).ToList();
                    postModel.id       = item.id;
                    postModel.title    = item.Title;
                    postModel.userid   = item.Userid;
                    postModel.username = item.User.Name;
                    postModel.image    = item.User.Image;
                    postModel.time     = item.Time;
                    postModel.visit    = item.Visit;
                    postModel.relpy    = postreply.Count();
                    if (item.Essence == 1)
                    {
                        postModel.essence = "精";
                    }
                    listpost.Add(postModel);
                }
                listpost = listpost.ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                //判断是否为ajax请求
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_Post", listpost));
                }
            }
            return(View(listpost));
        }