Ejemplo n.º 1
0
 public JsonResult Delrecord(FormCollection fc)
 {
     BBSSite.MyPublic.LoginStatus IStatus = new BBSSite.MyPublic.LoginStatus();
     if (IStatus.IsLogin)
     {
         int FMID;
         if (int.TryParse(fc["FMID"], out FMID))
         {
             using (DB_BBSEntities db = new DB_BBSEntities())
             {
                 tb_ForumMain fm = new tb_ForumMain()
                 {
                     ID = FMID
                 };
                 tb_ForumMain updateForumMain = db.tb_ForumMain.Attach(fm);
                 updateForumMain.Isdelete = true;
                 db.Entry(updateForumMain).Property(P => P.Isdelete).IsModified = true;
                 db.Configuration.ValidateOnSaveEnabled = false;
                 bool IsUpdate = db.SaveChanges() > 0;
                 db.Configuration.ValidateOnSaveEnabled = false;
                 if (IsUpdate)
                 {
                     return(Json(new { ResultStatus = 1, ResultMsg = "操作成功!" }, JsonRequestBehavior.AllowGet));
                 }
             }
             return(Json(new { ResultStatus = 0, ResultMsg = "操作失败!" }, JsonRequestBehavior.AllowGet));
         }
         return(Json(new { ResultStatus = -1, ResultMsg = "参数验证失败!" }, JsonRequestBehavior.AllowGet));
     }
     return(Json(new { ResultStatus = -2, ResultMsg = "未登录!" }, JsonRequestBehavior.AllowGet));
 }
Ejemplo n.º 2
0
        public ActionResult MainContent(int id = 0, int CurrentPageindex = 1)
        {
            if (id == 0)                       //判断子专区id值是否为0
            {
                return(Goto("Index", "Home")); //执行跳转到上一次访问的动作,或跳转到指定的动作
            }
            bool IsLimit = false;              //定义权限变量

            ViewBag.IsLimit = false;           //将权限值赋予动态类型,用于视图中的访问
            //实例化用户登录状态类
            BBSSite.MyPublic.LoginStatus IStatus = new BBSSite.MyPublic.LoginStatus();
            if (IStatus.IsLogin)                                 //判断用户是否登录
            {
                tb_ForumClassify ForumClassify = null;           //定义子专区数据类
                using (DB_BBSEntities db = new DB_BBSEntities()) //实例化数据库上下文类
                {
                    //按照子专区id值查询该专区的其他信息
                    ForumClassify = db.tb_ForumClassify.Where(W => W.ID == id).FirstOrDefault();
                    if (ForumClassify != null)//如果查询数据不为空
                    {
                        //获取该专区的所属用户id,改用户可对该专区的帖子列表有执行操作权限
                        int ForumClassifyUserID = ForumClassify.ForumUserID;
                        //取出该子专区所属大板块专区的信息数据
                        tb_ForumArea ForumArea = db.tb_ForumArea.Where(W => W.ID == ForumClassify.ForumAreaID).FirstOrDefault();
                        //取出大板块专区的所属用户id
                        int ForumAreaUserID = ForumArea.UserID;
                        //如果当前登录用户与拥有子专区或大板块专区权限的用户相同
                        if (IStatus.LoginStatusEntity.ID == ForumClassifyUserID || IStatus.LoginStatusEntity.ID == ForumAreaUserID)
                        {
                            ViewBag.IsLimit = true;//该用户有执行操作权限
                            IsLimit         = true;
                        }
                    }
                }
            }
            PublicFunctions.SetUrls(ViewBag, Url);  //构造资源路径(js、css、image等)
            const int PageSize = 20, PageCount = 5; //定义每页显示数据总数及最多显示的页码
            //构造分页对象配置类
            ConfigPaging cp = new ConfigPaging(CurrentPageindex, PageSize, PageCount);
            ForumClassifyJoinForumMainEntity Model = null;   //要返回的数据模型

            using (DB_BBSEntities db = new DB_BBSEntities()) //实例化数据库上下文类
            {
                //按条件查询子专区表以及所属主贴表数据
                Model = db.tb_ForumClassify.Where(W => W.ID == id).Select(S => new ForumClassifyJoinForumMainEntity
                {
                    ID                = S.ID,
                    ClassifyName      = S.ClassifyName,
                    ClassifyInnerLogo = S.ClassifyInnerLogo,
                    UsersByBanzhu     = S.tb_UsersByCustomer,
                    ForumMain         = (ICollection <tb_ForumMain>)S.tb_ForumMain.Where(Where => Where.Isdelete == false && ((!IsLimit && Where.IsExamine == 1) || IsLimit)).OrderByDescending(O => O.ID).Skip(cp.StartRow).Take(PageSize)
                }).FirstOrDefault();
                //以下为与ForumMain(帖子)表对应的外键表信息
                Model.ReplyNumber     = Model.ForumMain.Select(S => S.tb_ForumInfoStatus.Where(W => W.ForumMainID == S.ID).First().ReplyNumber).ToList();                                                                 //统计回复次数
                Model.SeeNumber       = Model.ForumMain.Select(S => S.tb_ForumInfoStatus.Where(W => W.ForumMainID == S.ID).First().SeeNumber).ToList();                                                                   //统计查看次数
                Model.LastReplyUser   = Model.ForumMain.Select(S => S.tb_ForumInfoStatus.Where(W => W.ForumMainID == S.ID).First().tb_UsersByCustomer.UserName).ToList();                                                 //最后回复人
                Model.UsersByCustomer = Model.ForumMain.Select(S => S.tb_UsersByCustomer).ToList();                                                                                                                       //发帖人
                Model.ImgUrl          = Model.ForumMain.Select(S => (S.IsRecommend ? "pin_1.gif" : "folder_new.gif")).ToList();                                                                                           //推荐帖与普通帖logo
                Model.FMType          = Model.ForumMain.Select(S => (S.IsRecommend ? "日月精华" : "最新帖子")).ToList();                                                                                                          //推荐贴与普通帖提示标题
                //以下为总的统计数据
                Model.TotalForumCount = db.tb_ForumMain.Count(W => W.Isdelete == false && W.ForumClassifyID == id);                                                                                                       //总帖子数
                Model.TotalReplyCount = db.tb_ForumMain.Where(W => W.Isdelete == false && W.ForumClassifyID == id).ToList().Aggregate(0, (count, current) => count + current.tb_ForumInfoStatus.Sum(S => S.ReplyNumber)); //总回复数
                Model.TotalSeeCount   = db.tb_ForumMain.Where(W => W.Isdelete == false && W.ForumClassifyID == id).ToList().Aggregate(0, (count, current) => count + current.tb_ForumInfoStatus.Sum(S => S.SeeNumber));   //只查看数
            }
            cp.GetPaging(ViewBag, Model.TotalForumCount);                                                                                                                                                                 //绑定分页数据
            ViewBag.curid = id;                                                                                                                                                                                           //此id为传入的所属专区ID,将在下次分页时带入
            return(View(Model));                                                                                                                                                                                          //返回视图
        }