//根级回复
        private int GetRootId(int pId)
        {
            if (pId == 0)
                return pId;
            else
            {
                var parent = new Course_UnitReplyDetailBLL().GetModel(pId, "");

                if (parent.ParentReplyId.Value == 0)
                {
                    return parent.Id;
                }
                else
                {
                    var root = new Course_UnitReplyDetailBLL().GetModel(parent.ParentReplyId.Value, "");
                    return root.Id;
                }
            }
        }
        //回复
        public JsonResult ReplyUnitContent(int uId, int classId, int accountId, int pId, string Content)
        {
            try
            {
                var bll = new Course_UnitReplyDetailBLL();
                var rootId = 0;
                rootId = GetRootId(pId);

                var model = new Course_UnitReplyDetail();
                model.UnitContent = uId;
                model.ClassId = classId;
                model.Content = Content;
                model.AccountId = accountId;
                model.Display = true;
                model.ParentReplyId = rootId;
                model.Delflag = false;
                model.CreateDate = DateTime.Now;
                bll.Add(model);
                return Json(new { Code = 0, Msg = "操作成功" }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return Json(new { Code = -1, Msg = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }
 //删除回复
 public JsonResult DeleteUnitContent(int Id)
 {
     try
     {
         var bll = new Course_UnitReplyDetailBLL();
         var model = bll.GetModel(Id, "");
         model.Delflag = true;
         bll.Update(model);
         return Json(new { Code = 0, Msg = "操作成功" }, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         return Json(new { Code = -1, Msg = ex.Message }, JsonRequestBehavior.AllowGet);
     }
 }
        /// <summary>
        /// 讨论新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult EditCourseUnitReply(Course_UnitReplyDetail model)
        {
            //此处借用model.AttList传递TrainingId
            if (this.GetCourseIsOver(model.ClassId, int.Parse(model.AttList), model.AccountId))
                return Json(new { Result = false, Msg = "提交失败.当前课程已结束,不能执行该操作!" }, JsonRequestBehavior.AllowGet);

            model.AttList = string.Empty;

            var UnitContentBll = new Course_UnitContentBLL();
            var ReplyBll = new Course_UnitReplyDetailBLL();

            var Model_UnitContent = UnitContentBll.GetModel(model.UnitContent, string.Empty);
            var iUnitType = Model_UnitContent.UnitType;//[1文本,2影音教材,3讨论,4作业,5测试,6结业考试]

            if (model.Id == 0)//新增
            {
                model.Delflag = false;
                model.Display = true;
                model.CreateDate = DateTime.Now;

                if (iUnitType == 3)//仅当活动为讨论时,计分(视频下的讨论不再记分)
                    this.ScoreSet(2, 0, 0, 0, true, model);//设置分数并更新讨论的进度

                if (ReplyBll.Add(model))
                {
                    return Json(new { Result = true, Msg = "提交成功!" }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json(new { Result = true, Msg = "提交失败!" }, JsonRequestBehavior.AllowGet);
                }
            }
            else//[删除] 修改DelFlag = 1
            {
                if (model.ParentReplyId == 0)
                {
                    if (ReplyBll.Update(model.Id))
                    {
                        if (iUnitType == 3)//仅当活动为讨论时,计分(视频下的讨论不再记分)
                            this.ScoreSet(2, 0, 0, 0, false, model);//设置分数并更新讨论的进度

                        return Json(new { Result = true, Msg = "话题删除成功!" }, JsonRequestBehavior.AllowGet);
                    }
                    else
                    {
                        return Json(new { Result = false, Msg = "话题删除失败!" }, JsonRequestBehavior.AllowGet);
                    }
                }
                else
                {
                    if (ReplyBll.Update(model.Id))
                    {
                        if (iUnitType == 3)//仅当活动为讨论时,计分(视频下的讨论不再记分)
                            this.ScoreSet(2, 0, 0, 0, false, model);//设置分数并更新讨论的进度

                        return Json(new { Result = true, Msg = "回复删除成功!" }, JsonRequestBehavior.AllowGet);
                    }
                    else
                    {
                        return Json(new { Result = false, Msg = "回复删除失败!" }, JsonRequestBehavior.AllowGet);
                    }
                }
            }
        }
        /// <summary>
        /// 设置分数
        /// </summary>
        /// <param name="iUnitType">//1阅读,2讨论
        /// <param name="IsAdd">True:新增 False:删除</param>
        /// <param name="obj">数据对象</param>
        private void ScoreSet(int iUnitType, int? iUnitContent = 0, int iClassId = 0, int iTrainingId = 0, bool IsAdd = false, Object obj = null)
        {
            var scheduleBll = new Member_ClassUnitContentScheduleBLL();
            var replyBll = new Course_UnitReplyDetailBLL();

            int iPlanId = 0, iAccountId = 0, iUnitId = 0;
            double dblScore = 0;
            var stbSqlWhere = new StringBuilder();

            if (iUnitType == 1)
            {
                iPlanId = Code.SiteCache.Instance.PlanId;
                iAccountId = Code.SiteCache.Instance.LoginInfo.UserId;

                stbSqlWhere.AppendFormat(" ClassId = {0} AND TrainingId = {1} AND AccountId = {2} AND UnitContent = {3} AND Status = 1 AND Delflag = 0",
                    iClassId, iTrainingId, iAccountId, iUnitContent);

                var List_Schedule = scheduleBll.GetList(stbSqlWhere.ToString(), string.Empty);
                if (List_Schedule != null && List_Schedule.Count > 0 && List_Schedule[0].score == null)//当存在记录,并且Score=null时记录分数
                {
                    Web.Code.ScoreSetHelper.ScoreSet(iUnitContent, iUnitType, iClassId, iPlanId, iAccountId, dblScore);
                }
            }
            else if (iUnitType == 2)//讨论  参与次数要 >=1
            {
                var model = obj as Course_UnitReplyDetail;
                iUnitContent = model.UnitContent;
                iClassId = model.ClassId;
                iPlanId = Code.SiteCache.Instance.PlanId;
                iAccountId = model.AccountId;
                stbSqlWhere.AppendFormat(" ClassId = {0} AND AccountId = {1} AND UnitContent = {2} AND Display = 1 AND Delflag = 0",
                        iClassId, iAccountId, iUnitContent);

                var List_ReplyDetail = replyBll.GetList(stbSqlWhere.ToString(), string.Empty);
                if (List_ReplyDetail != null)
                {
                    if (IsAdd)
                    {
                        if (List_ReplyDetail.Count <= 0)
                        {
                            Web.Code.ScoreSetHelper.ScoreSet(iUnitContent, iUnitType, iClassId, iPlanId, iAccountId, dblScore, true);
                        }
                    }
                    else
                    {
                        Web.Code.ScoreSetHelper.ScoreSet(iUnitContent, iUnitType, iClassId, iPlanId, iAccountId, dblScore, false);
                    }
                }

                //获取当前活动的UnitId
                var unitContentBll = new Course_UnitContentBLL();
                var Model_UnitContent = unitContentBll.GetModel(iUnitContent.Value, string.Empty);
                iUnitId = Model_UnitContent.UnitId == null ? 0 : Model_UnitContent.UnitId.Value;
                //获取TrainingId
                var unitDetailBll = new Course_UnitDetailBLL();
                var Model_UnitDetail = unitDetailBll.GetModel(iUnitId, string.Empty);
                iTrainingId = Model_UnitDetail.TrainingId == null ? 0 : Model_UnitDetail.TrainingId.Value;
                //更新总进度
                this.UpdateOverallProgress(iUnitId, iClassId, iTrainingId, iAccountId, iUnitContent.Value);//分数添加之后更新总进度
            }
        }
        /// <summary>
        /// 获取[学习讨论]信息 -- 话题
        /// </summary>
        private void GetCourseUnitDetail_Topic(int iUnitContent)
        {
            var grpBll = new Class_GroupBLL();
            var ReplyBll = new Course_UnitReplyDetailBLL();
            var stbSqlWhere = new StringBuilder();
            var Topic_Reply_Dictry = new Dictionary<Course_UnitReplyDetailOther, List<Course_UnitReplyDetailOther>>();//页面绑定的字典信息
            var List_Course_UnitReplyDetail_ShowTopic = new List<Course_UnitReplyDetailOther>();//话题
            var List_Course_UnitReplyDetail_Reply = new List<Course_UnitReplyDetailOther>();//回复
            var strOrderBy = string.Empty;
            int iAccountId = 0, iClassId = 0;

            int.TryParse(Convert.ToString(Request["ClassId"]) == "" ? "0" : QueryString.Decrypt(Request["ClassId"]), out iClassId);//获取 ClassId
            iAccountId = Code.SiteCache.Instance.LoginInfo.UserId;

            //获取数据总数
            int iTopicRecordCount = ReplyBll.GetListTopicTotalCount(iClassId, iUnitContent);
            int iTopicPageSize = 10, iTopicPageIndex = 0;
            int iTopicPageCount = (int)Math.Ceiling((double)iTopicRecordCount / iTopicPageSize);
            int.TryParse(Request["pageIndex"], out iTopicPageIndex);
            if (iTopicPageIndex < 1)
                iTopicPageIndex = 1;
            else if (iTopicPageIndex > iTopicPageCount)
                iTopicPageIndex = iTopicPageCount;

            List_Course_UnitReplyDetail_ShowTopic = ReplyBll.GetListTopicOther(iTopicPageSize, iTopicPageIndex, iClassId, iUnitContent, out iTopicRecordCount);
            if (List_Course_UnitReplyDetail_ShowTopic != null && List_Course_UnitReplyDetail_ShowTopic.Count > 0)
            {
                foreach (var topicModel in List_Course_UnitReplyDetail_ShowTopic)
                {
                    List_Course_UnitReplyDetail_Reply = ReplyBll.GetListReplyOther(iClassId, iUnitContent, topicModel.CourseUnitReplyDetail.Id);
                    Topic_Reply_Dictry.Add(topicModel, List_Course_UnitReplyDetail_Reply);
                }
            }

            ViewBag.TopicRecordCount = iTopicRecordCount;
            ViewBag.TopicPageCount = iTopicPageCount;
            ViewBag.TopicPageIndex = iTopicPageIndex;
            ViewBag.TopicPageSize = iTopicPageSize;
            ViewBag.Topic_Reply_Dictry = Topic_Reply_Dictry;
        }