예제 #1
0
        /// <summary>
        /// 用户级别删除
        /// </summary>
        /// <returns></returns>
        public ActionResult LevelEdit()
        {
            int levelid = Request["id"].ToInt();
            var massage = "删除失败";

            if (levelid > 0)
            {
                using (var club = new ClubEntitie())
                {
                    var level = club.Level.FirstOrDefault(a => a.id == levelid);
                    if (level != null)
                    {
                        club.Level.Remove(level);
                        club.SaveChanges();
                        massage = "删除成功";
                    }
                }
            }
            else
            {
                massage = "数据格式错误";
            }
            ShowMassage(massage);

            return(RedirectToAction("Level"));
        }
예제 #2
0
        public ActionResult Login()
        {
            var account = Request["account"];
            var psw     = Request["password"];

            if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(psw))
            {
                ShowMassage("用户名或密码不能为空");
                return(RedirectToAction("Index"));
            }
            using (var club = new ClubEntitie())
            {
                psw = psw.MD5Encoding(account);
                var user = club.User.FirstOrDefault(a => a.Account == account);
                if (user == null)
                {
                    ShowMassage("用户名不存在");
                    return(RedirectToAction("Index"));
                }
                if (user.Password != psw)
                {
                    ShowMassage("密码错误");
                    return(RedirectToAction("Index"));
                }
                if (!user.IsAdmin)
                {
                    ShowMassage("你不是管理员,无权登录");
                    return(RedirectToAction("Index"));
                }
                Session["adminuser"] = user;
            }
            return(Redirect("/Admin/Post"));
        }
예제 #3
0
        public ActionResult LevelInformation()
        {
            var message = "";
            int levelid = int.Parse(Request["id"]);
            var name    = Request["name"];
            var level   = new Level();

            using (var club = new ClubEntitie())
            {
                if (levelid == 0)
                {
                    club.Level.Add(level);
                    message = "新增成功";
                }
                else
                {
                    level   = club.Level.FirstOrDefault(a => a.id == levelid);
                    message = "更新成功";
                }
                level.Name = name;
                ShowMassage(message);
                club.SaveChanges();
            }

            return(RedirectToAction("Level"));
        }
예제 #4
0
 public ActionResult Login(UserLogin UserLogin)
 {
     if (string.IsNullOrEmpty(UserLogin.Account) || string.IsNullOrEmpty(UserLogin.Password))
     {
         ShowMassage("用户名或密码不能为空");
         return(RedirectToAction("Login"));
     }
     using (var club = new ClubEntitie())
     {
         UserLogin.Password = UserLogin.Password.MD5Encoding(UserLogin.Account);
         var user = club.User.OrderByDescending(a => a.id).Include(a => a.Level).FirstOrDefault(a => a.Account == UserLogin.Account);
         if (user == null)
         {
             ShowMassage("用户名不存在");
             return(RedirectToAction("Login"));
         }
         if (user.Password != UserLogin.Password)
         {
             ShowMassage("密码错误");
             TempData["account"] = UserLogin.Account;
             return(RedirectToAction("Login"));
         }
         Session["loginuser"] = user;
         ViewBag.username     = UserLogin.Account;
     }
     return(Redirect("/Post"));
 }
예제 #5
0
        public ActionResult Information(int?id)
        {
            int userid = id ?? 0;
            var user   = new User();

            using (var club = new ClubEntitie())
            {
                if (userid != 0)
                {
                    user = club.User.Include(a => a.Level).FirstOrDefault(a => a.id == userid);
                }
                var selectlistitem = new List <SelectListItem>();
                var level          = club.Level.ToList();
                foreach (var item in level)
                {
                    var selectitem = new SelectListItem();
                    selectitem.Text  = item.Name;
                    selectitem.Value = item.id.ToString();
                    if (userid != 0 && (user.Levelid == item.id))
                    {
                        selectitem.Selected = true;
                    }
                    selectlistitem.Add(selectitem);
                }
                ViewBag.SelectItem = selectlistitem;
            }

            return(View(user));
        }
예제 #6
0
        public ActionResult TypeInformation()
        {
            int typeid  = Request["id"].ToInt();
            var name    = Request["name"];
            var type    = new Type();
            var massage = "";

            using (var club = new ClubEntitie())
            {
                if (typeid > 0)
                {
                    type    = club.Type.FirstOrDefault(a => a.id == typeid);
                    massage = "更新成功";
                }
                else
                {
                    club.Type.Add(type);
                    massage = "添加成功";
                }
                type.Name = name;
                club.SaveChanges();
            }
            ShowMassage(massage);
            return(RedirectToAction("Type"));
        }
예제 #7
0
 public ActionResult Register(UserRegister UserRegister)
 {
     using (var db = new ClubEntitie())
     {
         var user = db.User.ToList();
         foreach (var item in user)
         {
             if (item.Account == UserRegister.Account)
             {
                 ShowMassage("账号已存在");
                 return(View());
             }
         }
         var useradd = new User();
         useradd.Account          = UserRegister.Account;
         useradd.Name             = UserRegister.Name;
         useradd.Password         = UserRegister.Password.MD5Encoding(UserRegister.Account);
         useradd.Levelid          = 1;
         useradd.RegistrationTime = DateTime.Now;
         db.User.Add(useradd);
         db.SaveChanges();
         ShowMassage("注册成功,请登录");
     }
     return(View());
 }
예제 #8
0
        /// <summary>
        /// 用户删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Delete(int id)
        {
            int userid  = Request["id"].ToInt();
            var massage = "删除失败";

            if (userid > 0)
            {
                using (var club = new ClubEntitie())
                {
                    var user = club.User.FirstOrDefault(a => a.id == userid);
                    if (user != null)
                    {
                        //删除
                        //club.User.Remove(user);

                        //逻辑删除
                        user.IsAbort = true;
                        club.SaveChanges();
                        massage = "删除成功";
                    }
                }
            }
            else
            {
                massage = "数据格式错误";
            }
            ShowMassage(massage);

            return(RedirectToAction("Index"));
        }
예제 #9
0
        /// <summary>
        /// 用户列表
        /// </summary>
        /// <param name="id"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public ActionResult Index(int?id, int?size, int?isselect)
        {
            pageIndex = id ?? pageIndex;
            pageSize  = size ?? pageSize;
            //该参数用于判断用户角色
            levelid = isselect ?? levelid;
            var kw = Request["kw"];
            PagedList <User> pageList;

            using (var club = new ClubEntitie())
            {
                var list = club.User.Where(a => a.IsAbort == false).OrderByDescending(a => a.id).Include(a => a.Level);
                if (!string.IsNullOrEmpty(kw))
                {
                    list = list.Where(a => a.Account.Contains(kw) || a.Name.Contains(kw));
                }
                if (levelid > 0)
                {
                    list = list.Where(a => a.Levelid == levelid);
                }
                pageList = list.ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_User", pageList));
                }
            }

            return(View(pageList));
        }
예제 #10
0
 public ActionResult New()
 {
     using (var db = new ClubEntitie())
     {
         var type = db.Type.ToList();
         ViewBag.type = type;
     }
     return(View());
 }
예제 #11
0
        /// <summary>
        /// 帖子浏览
        /// </summary>
        /// <returns></returns>
        public ActionResult Browse()
        {
            var postid = Request["postid"].ToInt();

            if (postid > 0)
            {
                using (var db = new ClubEntitie())
                {
                    var post = db.Post.Include(a => a.User).Include(a => a.Type).FirstOrDefault(a => a.id == postid);
                    var user = db.User.OrderByDescending(a => a.id).Include(a => a.Level).ToList();
                    ViewBag.User = user;
                    //查询赞帖子的用户
                    var praiserecord = db.PraiseRecord.OrderByDescending(a => a.id).Include(a => a.User).Where(a => a.Postid == postid).ToList();
                    ViewBag.praiserecord = praiserecord;
                    var listpraiserecord = new List <PraiserecordModel>();
                    foreach (var item in praiserecord)
                    {
                        var praiserecordmodel = new PraiserecordModel();
                        praiserecordmodel.postid    = item.Postid;
                        praiserecordmodel.userid    = item.Userid;
                        praiserecordmodel.username  = item.User.Name;
                        praiserecordmodel.userimage = item.User.Image;
                        praiserecordmodel.time      = item.CreateTime;
                        listpraiserecord.Add(praiserecordmodel);
                    }
                    ViewData["praiserecord"] = listpraiserecord;
                    //查询收藏帖子的用户
                    var collection = db.Collection.OrderByDescending(a => a.id).Include(a => a.User).ToList();
                    ViewBag.collection = collection;
                    //查询帖子回复的信息
                    var reply     = db.Reply.OrderByDescending(a => a.id).Include(a => a.User).Where(a => a.Postid == postid).ToList();
                    var listreply = new List <ReplyModel>();
                    foreach (var item in reply)
                    {
                        var replyModel = new ReplyModel();
                        replyModel.postid       = item.Postid;
                        replyModel.userid       = item.Userid;
                        replyModel.username     = item.User.Name;
                        replyModel.userlevel    = item.User.Level.Name;
                        replyModel.userimage    = item.User.Image;
                        replyModel.content      = item.Contents;
                        replyModel.recoverytime = item.Recoverytime;
                        listreply.Add(replyModel);
                    }
                    ViewData["reply"] = listreply;
                    //更新帖子访问量
                    post.Visit += 1;
                    db.SaveChanges();
                    return(View(post));
                }
            }
            return(View());
        }
예제 #12
0
        public ActionResult LevelInformation(int?id)
        {
            int levelid = id ?? 0;
            var level   = new Level();

            if (levelid != 0)
            {
                using (var club = new ClubEntitie())
                {
                    level = club.Level.FirstOrDefault(a => a.id == levelid);
                }
            }
            return(View(level));
        }
예제 #13
0
        public ActionResult TypeInformation(int?id)
        {
            var typeid = id ?? 0;
            var type   = new Type();

            using (var club = new ClubEntitie())
            {
                if (typeid > 0)
                {
                    type = club.Type.FirstOrDefault(a => a.id == typeid);
                }
            }
            return(View(type));
        }
예제 #14
0
        /// <summary>
        /// 帖子列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Index(int?id, int?size, int?isselect, int?type)
        {
            pageIndex = id ?? pageIndex;
            pageSize  = size ?? pageSize;
            //该参数用于判断审核分类
            isFeatured = isselect ?? isFeatured;
            //该参数用于判断帖子类型
            selectType = type ?? selectType;
            var kw = Request["kw"];
            PagedList <Post> pageList;
            var selecttypelist = new List <SelectListItem>();

            using (var club = new ClubEntitie())
            {
                var typelist   = club.Type.ToList();
                var selectitem = new SelectListItem();
                selectitem.Text     = "全部";
                selectitem.Value    = "0";
                selectitem.Selected = true;
                selecttypelist.Add(selectitem);
                foreach (var item in typelist)
                {
                    selectitem       = new SelectListItem();
                    selectitem.Text  = item.Name;
                    selectitem.Value = item.id.ToString();
                    selecttypelist.Add(selectitem);
                }
                ViewBag.type = selecttypelist;
                var list = club.Post.OrderByDescending(a => a.id).Include(a => a.User).Include(a => a.Type).Where(a => a.IsAbout == false);
                if (!string.IsNullOrEmpty(kw))
                {
                    list = list.Where(a => a.Title.Contains(kw) || a.Contents.Contains(kw));
                }
                if (isFeatured == 0 || isFeatured == 1)
                {
                    bool featuredis = isFeatured.ToBit();
                    list = list.Where(a => a.IsFeatured == featuredis);
                }
                if (selectType > 0)
                {
                    list = list.Where(a => a.Typeid == selectType);
                }
                pageList = list.ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_Post", pageList));
                }
            }
            return(View(pageList));
        }
예제 #15
0
        /// <summary>
        /// 管理员个人信息跳转
        /// </summary>
        /// <returns></returns>
        public ActionResult InformationJump()
        {
            var userid = Request["id"].ToInt();

            if (userid > 0)
            {
                using (var club = new ClubEntitie())
                {
                    var user = club.User.Include(a => a.Level).FirstOrDefault(a => a.id == userid);
                    Session["loginuser"] = user;
                }
                return(Redirect("/User/Index?id=" + userid));
            }
            return(View());
        }
예제 #16
0
        public ActionResult Information()
        {
            var id           = Request["id"].ToInt();
            int isfeaturedid = Request["isfeaturedid"].ToInt();
            int typeid       = Request["typeid"].ToInt();

            using (var club = new ClubEntitie())
            {
                var post = club.Post.FirstOrDefault(a => a.id == id);
                post.Typeid     = typeid;
                post.IsFeatured = isfeaturedid.ToBit();
                club.SaveChanges();
            }
            ShowMassage("更新成功");
            return(RedirectToAction("Index"));
        }
예제 #17
0
        /// <summary>
        /// 用户赞贴、收藏
        /// </summary>
        /// <returns></returns>
        public ActionResult PraiseCollect()
        {
            var key    = Request["key"].ToInt();
            var postid = Request["postid"].ToInt();
            var userid = Request["userid"].ToInt();

            using (var db = new ClubEntitie())
            {
                if (key == 1)
                {
                    var praiserecord = new PraiseRecord();
                    praiserecord.Postid     = postid;
                    praiserecord.Userid     = userid;
                    praiserecord.CreateTime = DateTime.Now;
                    db.PraiseRecord.Add(praiserecord);
                    db.SaveChanges();
                }
                else
                {
                    var collection = new Collection();
                    collection.Postid     = postid;
                    collection.Userid     = userid;
                    collection.CreateTime = DateTime.Now;
                    db.Collection.Add(collection);
                    db.SaveChanges();
                }
                //查询赞帖子的用户
                var praiserecords = db.PraiseRecord.OrderByDescending(a => a.id).Include(a => a.User).Where(a => a.Postid == postid).ToList();
                ViewBag.praiserecord = praiserecords;
                var listpraiserecord = new List <PraiserecordModel>();
                foreach (var item in praiserecords)
                {
                    var praiserecordmodel = new PraiserecordModel();
                    praiserecordmodel.postid    = item.Postid;
                    praiserecordmodel.userid    = item.Userid;
                    praiserecordmodel.username  = item.User.Name;
                    praiserecordmodel.userimage = item.User.Image;
                    praiserecordmodel.time      = item.CreateTime;
                    listpraiserecord.Add(praiserecordmodel);
                }
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_PraiseRecord", listpraiserecord));
                }
            }
            return(RedirectToAction("Browse"));
        }
예제 #18
0
        /// <summary>
        /// 帖子类型
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Type(int?id, int?size)
        {
            pageIndex = id ?? pageIndex;
            pageSize  = size ?? pageSize;
            PagedList <Type> pageList;

            using (var club = new ClubEntitie())
            {
                var typelist = club.Type.OrderByDescending(a => a.id);
                pageList = typelist.ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_Type", pageList));
                }
            }
            return(View(pageList));
        }
예제 #19
0
        /// <summary>
        /// 用户级别
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Level(int?id)
        {
            var pageIndex = id ?? 1;
            int pageSize  = 4;
            PagedList <Level> pageList;
            var user = new List <Level>();

            using (var club = new ClubEntitie())
            {
                pageList = club.Level.OrderByDescending(a => a.id).ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_Level", pageList));
                }
            }
            return(View(pageList));
        }
예제 #20
0
        /// <summary>
        /// 帖子类型删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult TypeEdit(int id)
        {
            var typeid  = id;
            var massage = "该类型删除失败!";

            using (var club = new ClubEntitie())
            {
                var type = club.Type.FirstOrDefault(a => a.id == typeid);
                if (type != null)
                {
                    type.IsAbout = true;
                    club.SaveChanges();
                    massage = "删除成功";
                }
            }
            ShowMassage(massage);
            return(RedirectToAction("Type"));
        }
예제 #21
0
        public ActionResult Edit(int id)
        {
            int postid  = id;
            var massage = "删除失败";

            if (postid != 0)
            {
                using (var club = new ClubEntitie())
                {
                    var post = club.Post.FirstOrDefault(a => a.id == postid);
                    post.IsAbout = true;
                    club.SaveChanges();
                    massage = "删除成功";
                }
            }
            ShowMassage(massage);
            return(RedirectToAction("Index"));
        }
예제 #22
0
        public ActionResult Information()
        {
            var message = "";
            //var id = int.Parse(Request["id"]);
            int id       = Request["id"].ToInt();
            var name     = Request["name"];
            var levleid  = int.Parse(Request["levelid"]);
            var gold     = int.Parse(Request["gold"]);
            var image    = Request["image"];
            var password = Request["password"];

            using (var club = new ClubEntitie())
            {
                var user = new User();
                if (id == 0)
                {
                    user.Account = Request["account"];
                    club.User.Add(user);
                    message = "新增成功";
                }
                else
                {
                    id      = int.Parse(Request["id"]);
                    user    = club.User.FirstOrDefault(a => a.id == id);
                    message = "更新成功";
                }
                //判断密码是否更新
                if (!string.IsNullOrEmpty(password))
                {
                    user.Password = password.MD5Encoding(user.Account);
                }
                user.Name    = name;
                user.Levelid = levleid;
                user.Gold    = gold;
                user.Image   = image;
                club.SaveChanges();
            }
            ShowMassage(message);

            return(RedirectToAction("Index"));
        }
예제 #23
0
        /// <summary>
        /// 批量审批、删除操作
        /// </summary>
        /// <returns></returns>
        public ActionResult BatchOperation()
        {
            var str = Request["str"];

            //判断str是否为空
            if (!string.IsNullOrWhiteSpace(str))
            {
                //将str拆分成字符数组
                string[]         split = str.Split(new char[] { '|' });
                PagedList <Post> pageList;
                using (var club = new ClubEntitie())
                {
                    for (int i = 0; i < split.Length; i++)
                    {
                        int postid = split[i].ToInt();
                        var post   = club.Post.FirstOrDefault(a => a.id == postid);
                        if (post != null)
                        {
                            //split[0]为1,则为批量删除操作;
                            //split[0]为2,则为批量审核操作;
                            if (split[0] == "1")
                            {
                                post.IsAbout = true;
                            }
                            else if (split[0] == "2")
                            {
                                post.IsFeatured = true;
                            }
                            club.SaveChanges();
                        }
                    }
                    if (Request.IsAjaxRequest())
                    {
                        var list = club.Post.OrderByDescending(a => a.id).Include(a => a.User).Include(a => a.Type).Where(a => a.IsAbout == false);
                        pageList = list.ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                        return(PartialView("_Post", pageList));
                    }
                }
            }
            return(View());
        }
예제 #24
0
        public ActionResult Information(int?id)
        {
            var postid = id ?? 0;
            var post   = new Post();

            using (var club = new ClubEntitie())
            {
                post = club.Post.Include(a => a.Type).Include(a => a.User).FirstOrDefault(a => a.id == postid);
                var selectlisttype = new List <SelectListItem>();
                var selectlistis   = new List <SelectListItem>();
                //帖子类型下拉
                var type = club.Type.ToList();
                foreach (var item in type)
                {
                    var selectitem = new SelectListItem();
                    selectitem.Text  = item.Name;
                    selectitem.Value = item.id.ToString();
                    if (post.Typeid == item.id)
                    {
                        selectitem.Selected = true;
                    }
                    selectlisttype.Add(selectitem);
                }
                ViewBag.type = selectlisttype;
                //是否审核下拉
                string[,] isfeatured = { { "0", "未审核" }, { "1", "已审核" } };
                for (int i = 0; i < 2; i++)
                {
                    var selectitem = new SelectListItem();
                    selectitem.Text  = isfeatured[i, 1];
                    selectitem.Value = isfeatured[i, 0];
                    if (post.IsFeatured == i.ToBit())
                    {
                        selectitem.Selected = true;
                    }
                    selectlistis.Add(selectitem);
                }
                ViewBag.isfeatured = selectlistis;
            }
            return(View(post));
        }
예제 #25
0
        [ValidateInput(false)]//允许传html代码格式的值
        public ActionResult Replysave()
        {
            int    postid  = Request["postid"].ToInt();
            int    userid  = Request["userid"].ToInt();
            string content = Request["content"].ToString();

            using (var db = new ClubEntitie())
            {
                var reply = new Reply();
                var post  = db.Post.FirstOrDefault(a => a.id == postid);
                reply.Postid       = postid;
                reply.Userid       = userid;
                reply.Contents     = content;
                reply.Recoverytime = DateTime.Now;
                //更新帖子最新的回复时间
                post.Recoverytime = DateTime.Now;
                db.Reply.Add(reply);
                db.SaveChanges();
                //查询帖子回复的信息
                var listreply      = db.Reply.OrderByDescending(a => a.id).Include(a => a.User).Where(a => a.Postid == postid).ToList();
                var listreplymodel = new List <ReplyModel>();
                foreach (var item in listreply)
                {
                    var replyModel = new ReplyModel();
                    replyModel.postid       = item.Postid;
                    replyModel.userid       = item.Userid;
                    replyModel.username     = item.User.Name;
                    replyModel.userlevel    = item.User.Level.Name;
                    replyModel.userimage    = item.User.Image;
                    replyModel.content      = item.Contents;
                    replyModel.recoverytime = item.Recoverytime;
                    listreplymodel.Add(replyModel);
                }
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_Comment", listreplymodel));
                }
            }
            return(View());
        }
예제 #26
0
        public ActionResult Save()
        {
            var typeId    = Request["typeId"].ToInt();
            var title     = Request["title"];
            var content   = Request["content"];
            var system    = Request["system"];
            var loginUser = (User)Session["loginuser"];

            using (var db = new ClubEntitie())
            {
                var post = new Post();
                post.Title    = title;
                post.Contents = content;
                post.Userid   = loginUser.id;
                post.Typeid   = typeId;
                post.System   = system;
                post.Time     = DateTime.Now;
                db.Post.Add(post);
                db.SaveChanges();
            }
            return(Redirect("/"));
        }
예제 #27
0
        /// <summary>
        /// 帖子审核
        /// </summary>
        /// <returns></returns>
        public ActionResult ToExamine()
        {
            var postid = Request["postid"].ToInt();
            PagedList <Post> pageList;

            using (var club = new ClubEntitie())
            {
                if (postid > 0)
                {
                    var post = club.Post.FirstOrDefault(a => a.id == postid);
                    post.IsFeatured = true;
                    club.SaveChanges();
                }
                if (Request.IsAjaxRequest())
                {
                    var list = club.Post.OrderByDescending(a => a.id).Include(a => a.User).Include(a => a.Type).Where(a => a.IsAbout == false);
                    pageList = list.ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                    return(PartialView("_Post", pageList));
                }
            }
            return(View());
        }
예제 #28
0
        /// <summary>
        /// 赞贴管理
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult PraiseRecord(int?id)
        {
            var pageIndex = id ?? 1;
            int pageSize  = 4;
            var kw        = Request["kw"];
            PagedList <PraiseRecord> pageList;

            using (var club = new ClubEntitie())
            {
                var list = club.PraiseRecord.OrderByDescending(a => a.id).Include(a => a.User).Include(a => a.Post);
                if (!string.IsNullOrEmpty(kw))
                {
                    list = list.Where(a => a.User.Name.Contains(kw) || a.Post.Title.Contains(kw));
                }
                pageList = list.ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_PraiseRecord", pageList));
                }
            }

            return(View(pageList));
        }
예제 #29
0
        public ActionResult Index(int?id)
        {
            int userid     = Request["userid"].ToInt();
            var user       = (User)Session["loginuser"];
            int requestkey = Request["key"].ToInt();

            if (requestkey != 0)
            {
                key = requestkey;
            }
            var pageIndex = id ?? 1;
            int pageSize  = 10;
            PagedList <Post>       pageListpost;
            PagedList <Collection> pageListcollection;
            PagedList <Reply>      pageListreply;

            using (var db = new ClubEntitie())
            {
                //判断用户访问自己的信息还是访问其他用户的信息
                if (userid <= 0)
                {
                    if (user != null)
                    {
                        userid = user.id;
                    }
                    else
                    {
                        ShowMassage("未知错误");
                        return(Redirect("/Post/Index"));
                    }
                }
                else
                {
                    user = db.User.Include(a => a.Level).FirstOrDefault(a => a.id == userid);
                }
                ViewBag.User = user;
                //帖子数量
                var post = db.Post.OrderByDescending(a => a.id).Where(a => a.Userid == userid);
                ViewBag.postnumber = post.Count();
                switch (key)
                {
                //帖子
                case 1:
                    ViewBag.url  = "_MyPost";
                    pageListpost = post.ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                    if (Request.IsAjaxRequest())
                    {
                        return(PartialView("_MyPost", pageListpost));
                    }
                    return(View(pageListpost));

                //回复
                case 2:
                    ViewBag.url = "_MyReply";
                    var listreply = new List <ReplyModel>();
                    var reply     = db.Reply.OrderByDescending(a => a.id).Include(a => a.Post).Include(a => a.User).Where(a => a.Userid == userid).DistinctBy(a => a.Postid);
                    pageListreply = reply.ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                    if (Request.IsAjaxRequest())
                    {
                        return(PartialView("_MyReply", pageListreply));
                    }
                    break;

                //收藏
                case 3:
                    ViewBag.url = "_MyDynamic";
                    var collection = db.Collection.OrderByDescending(a => a.id).Include(a => a.Post).Where(a => a.Userid == userid);
                    pageListcollection = collection.ToPagedList(pageIndex: pageIndex, pageSize: pageSize);
                    if (Request.IsAjaxRequest())
                    {
                        return(PartialView("_MyDynamic", pageListcollection));
                    }
                    break;

                //粉丝
                case 4:
                    break;
                }
            }
            return(View());
        }
예제 #30
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));
        }