コード例 #1
0
        //小组讨论
        public ActionResult ClassDiscuss(string classId, int? groupId, int unitId = 0, int pageIndex = 1, int pageIndex2 = 1)
        {
            var param_classId = Dianda.Common.QueryString.Decrypt(classId).ToInt();
            int totalPage = 0;
            int totalPage2 = 0;
            var classDetail = new Class_DetailBLL().GetModel(param_classId);

            var topicList = DataTableToListHelper<Dianda.AP.Model.Course_UnitContent>
               .ConvertToModel(PagingQueryBll.GetPagingDataTable(@"  Course_UnitContent
                INNER JOIN Course_UnitDetail ON Course_UnitContent.UnitId = Course_UnitDetail.Id"
               , @" Course_UnitDetail.Display = 1
                                                AND Course_UnitDetail.Delflag = 0
                                                AND Course_UnitContent.Display = 1
                                                AND Course_UnitContent.Delflag = 0
                                                AND Course_UnitDetail.TrainingId = " + classDetail.TraningId + @"
                                                AND UnitType = 3  ", " dbo.Course_UnitDetail.Id", 1, out totalPage, "Course_UnitContent.*", 50));

            ViewBag.topicList = topicList;

            ViewBag.currentTopic = unitId == 0 ? (topicList.Count > 0 ? topicList[0].Content : null) : new Course_UnitContentBLL().GetModel(unitId, "").Content;
            //ViewBag.currentTopicId = unitId == 0 ? (topicList.Count > 0 ? topicList[0].Id : 0) : unitId;

            //班级成员
            var allMember = new Member_ClassRegisterBLL()
                                     .GetList(" ClassId=" + param_classId + " and Delflag=0 and status=4", "")
                                     .GroupBy(s => s.AccountId);
            totalPage2 = allMember.Count();
            ViewBag.classMember = from c in allMember.Skip((pageIndex2 - 1) * 10).Take(10)
                                  select c.Key;

            var paramUnit = unitId == 0 ? (topicList.Count > 0 ? "r.UnitContent=" + topicList[0].Id : " 1=1 ") : " r.UnitContent= " + unitId;
            var where = paramUnit + " and r.ClassId=" + param_classId + " AND r.Delflag=0 AND r.ParentReplyId=0 AND r.Display=1 and r.AccountId!=0";
            if (groupId.HasValue)//有组条件
            {
                if (groupId == 0)
                {
                    where += @" and exists (SELECT 1 FROM  Member_ClassRegister m
                    INNER JOIN dbo.Class_GroupMember cgm ON m.AccountId = cgm.AccountId
                    INNER JOIN dbo.Class_Group cg ON cgm.GroupId=cg.Id
                    INNER JOIN dbo.Class_Detail c ON cg.ClassId=c.id
                    WHERE  r.AccountId = m.AccountId
                    AND m.ClassId=r.ClassId
                    AND m.status = 4
                    AND m.Delflag = 0)";
                }
                if (groupId == -1)
                {
                    where += @" and not exists (SELECT 1 FROM  Member_ClassRegister m
                    INNER JOIN dbo.Class_GroupMember cgm ON m.AccountId = cgm.AccountId
                    INNER JOIN dbo.Class_Group cg ON cgm.GroupId=cg.Id
                    INNER JOIN dbo.Class_Detail c ON cg.ClassId=c.id
                    WHERE  r.AccountId = m.AccountId
                    AND m.ClassId=r.ClassId
                    AND m.status = 4
                    AND m.Delflag = 0)";
                }
                if (groupId > 0)
                {
                    where += @" and exists (SELECT 1 FROM  Member_ClassRegister m
                    INNER JOIN dbo.Class_GroupMember cgm ON m.AccountId = cgm.AccountId
                    INNER JOIN dbo.Class_Group cg ON cgm.GroupId=cg.Id
                    INNER JOIN dbo.Class_Detail c ON cg.ClassId=c.id
                    WHERE  r.AccountId = m.AccountId
                    AND m.ClassId=r.ClassId
                    AND m.status = 4
                    AND m.Delflag = 0
                    AND cgm.GroupId= " + groupId + ")";
                }

            }
            else//默认全部组
            {
                where += @" and exists (SELECT 1 FROM  Member_ClassRegister m
                    INNER JOIN dbo.Class_GroupMember cgm ON m.AccountId = cgm.AccountId
                    INNER JOIN dbo.Class_Group cg ON cgm.GroupId=cg.Id
                    INNER JOIN dbo.Class_Detail c ON cg.ClassId=c.id
                    WHERE  r.AccountId = m.AccountId
                    AND m.ClassId=r.ClassId
                    AND m.status = 4
                    AND m.Delflag = 0)";
            }
            //Model
            var list = DataTableToListHelper<Dianda.AP.Model.Course_UnitReplyDetail>
               .ConvertToModel(PagingQueryBll.GetPagingDataTable("Course_UnitReplyDetail r", where, "r.id", pageIndex, out totalPage, "r.*", 3));

            var allGroup = new Class_GroupBLL().GetList(" ClassId=" + param_classId + " and Delflag=0 AND Display=1", "");

            ViewBag.GroupList = allGroup;
            //成员分页
            ViewBag.pageIndex2 = pageIndex2;
            ViewBag.totalPage2 = totalPage2;

            ViewBag.classId = classId;
            ViewBag.param_classId = param_classId;
            //讨论分页
            ViewBag.pageIndex = pageIndex;
            ViewBag.totalPage = totalPage;
            ViewBag.basecount = 3;

            ViewBag.accountId = SiteCache.Instance.LoginInfo.UserId;
            ViewBag.traningId = classDetail.TraningId;

            var classModel = new Class_DetailBLL().GetModel(param_classId);
            if (classModel != null)
            {
                ViewBag.CourseName = new Traning_DetailBLL().GetModel(classModel.TraningId, "").Title;
                ViewBag.ClassName = classModel.Title;

                var traningTeacher = new Traning_TeacherBLL().GetList(" Delflag=0 AND TraningId=" + classModel.TraningId, "");
                var teacherAccount = (traningTeacher != null && traningTeacher.Count > 0) ? new PlatformManager_DetailBLL().GetModel(traningTeacher.First().PlatformManagerId.Value, "").AccountId : 0;
                ViewBag.TraningTeacher = teacherAccount;
            }

            ViewBag.ManagerId = SiteCache.Instance.ManagerId;

            return View(list);
        }