Ejemplo n.º 1
0
 public JsonResult AddNew()
 {
     // 检查参数
     string chapterName = Request["name"];
     long seqNo, courseId;
     if (CommonHelper.IsNullOrEmptyOrWhiteSpace(chapterName) ||    // 章节名称为空.
         chapterName.Length > 50 ||
         !long.TryParse(Request["seqno"], out seqNo) ||            // 章节序号非整数.
         seqNo <= 0 ||                                             // 章节序号负数.
         !long.TryParse(Request["crsid"], out courseId) ||         // 课程编号非整数
         _courseBll.GetCourse(courseId) == null)                   // 课程不存在
     {
         return JsonHelper.GetJsonResult(_ERROR, "章节名 或 序号 错误");
     }
     Chapter chapter = new Chapter()
     {
         //Id = ,
         Name = chapterName,
         SeqNo = seqNo,
         CourseId = courseId,
     };
     // 更新
     _chapterBll.AddChapter(chapter);
     // 记录日志
     string log = string.Format("新增章节:名称‘{0}’;序号‘{1}’;所属课程‘{2}’",
         chapter.Name, chapter.SeqNo, chapter.CourseId);
     AdminOperationLogBll.AddAdminOperationLog(AdminUserId, log);
     // 跳转列表
     string url = string.Format("/Chapter/List/{0}", chapter.CourseId);
     return JsonHelper.GetJsonResult(_OK, "更新章节成功", url);
 }
Ejemplo n.º 2
0
 public int DeleteChapter(Chapter chapter)
 {
     var chptrs = from chptr in _dbContext.Chapters
                  where chptr.CourseId == chapter.CourseId && chptr.SeqNo > chapter.SeqNo
                  select chptr;
     foreach (var chptr in chptrs)
     {
         chptr.SeqNo -= 1L;
         _dbContext.Entry(chptr).State = EntityState.Modified;
     }
     _dbContext.Entry(chapter).State = EntityState.Deleted;
     return _dbContext.SaveChanges();
 }
Ejemplo n.º 3
0
        public void AddChapter(Chapter chapter)
        {
            if (chapter == null)
            {
                throw new ArgumentNullException("chapter");
            }

            int row = _dal.AddChapter(chapter);

            if (row <= 0)
            {
                string.Format("新增章节:{0}失败", chapter.Name).ThrowException();
            }
        }
Ejemplo n.º 4
0
        public void UpdateChapter(Chapter oldChapter, Chapter newChapter)
        {
            if (oldChapter == null || newChapter == null)
            {
                "oldChapter和newChapter都不能为空".ThrowException();
            }
            if (oldChapter.CourseId != newChapter.CourseId && newChapter.CourseId < 0L)
            {
                "章节Id不相同".ThrowException();
            }

            int row = _dal.UpdateChapter(oldChapter, newChapter);

            if (row <= 0)
            {
                string.Format("更新章节chapterId:{0}失败", newChapter.Id).ThrowException();
            }
        }
Ejemplo n.º 5
0
        public void DeleteChapter(long chapterId)
        {
            Chapter chapter = new ChapterBll(new HengNuoWangDBContext()).GetChapter(chapterId);
            if (chapter == null)
            {
                string.Format("不存在指定chapterId:{0}的章节", chapterId).ThrowException();
            }
            Chapter chptr = new Chapter()
            {
                Id = chapter.Id,
                SeqNo = chapter.SeqNo,
                CourseId = chapter.CourseId,
            };
            int row = _dal.DeleteChapter(chptr);

            if (row <= 0)
            {
                string.Format("删除章节chapterId:{0}失败", chapter.Id).ThrowException();
            }
        }
Ejemplo n.º 6
0
 public int UpdateChapter(Chapter oldChapter, Chapter newChapter)
 {
     long oldSeqNo = oldChapter.SeqNo;
     long newSeqNo = newChapter.SeqNo;
     long courseId = newChapter.CourseId;
     if (oldSeqNo < newSeqNo)
     {
         // 序号变大 => (oldSeqNo, newSeqNo]--
         var chptrs = from chptr in _dbContext.Chapters
                      where chptr.CourseId == courseId && chptr.SeqNo > oldSeqNo && chptr.SeqNo <= newSeqNo
                      select chptr;
         foreach (var chapter in chptrs)
         {
             chapter.SeqNo -= 1L;
             _dbContext.Entry(chapter).State = EntityState.Modified;
         }
     }
     else if (oldSeqNo > newSeqNo)
     {
         // 序号变小 => [newSeqNo, oldSeqNo)++
         var chptrs = from chptr in _dbContext.Chapters
                      where chptr.CourseId == courseId && chptr.SeqNo >= newSeqNo && chptr.SeqNo < oldSeqNo
                      select chptr;
         foreach (var chapter in chptrs)
         {
             chapter.SeqNo += 1L;
             _dbContext.Entry(chapter).State = EntityState.Modified;
         }
     }
     //else if (oldSeqNo == newSeqNo)
     //{
     //    // 只需要保存更新后的章节信息
     //}
     _dbContext.Entry(newChapter).State = EntityState.Modified;
     return _dbContext.SaveChanges();
 }
Ejemplo n.º 7
0
 public JsonResult Edit(long id)
 {
     // 检查请求
     string chapterName = Request["name"];
     long seqNo, courseId;
     Chapter oldChapter;
     if (CommonHelper.IsNullOrEmptyOrWhiteSpace(chapterName) ||
         chapterName.Length > 50 ||
         !long.TryParse(Request["seqno"], out seqNo) ||
         seqNo <= 0 ||
         !long.TryParse(Request["crsid"], out courseId) ||
         (oldChapter = new ChapterBll(new HengNuoWangDBContext()).GetChapter(chapterId: id)) == null)
     {
         return JsonHelper.GetJsonResult(_ERROR, "章节名 或 序号 错误");
     }
     Chapter newChapter = new Chapter()
     {
         Id = oldChapter.Id,
         Name = chapterName,
         SeqNo = seqNo,
         CourseId = oldChapter.CourseId,
     };
     if (oldChapter.Name == newChapter.Name && oldChapter.SeqNo == newChapter.SeqNo)
     {
         return JsonHelper.GetJsonResult(_ERROR, "章节名和序号都没有变化");
     }
     // 更新
     _chapterBll.UpdateChapter(oldChapter, newChapter);
     // 记录日志
     string log = string.Format("更新章节‘{0}’:章节名【{1}=>{2}】;段落序号【{3}=>{4}】;所属课程【{5}=>{6}】",
         oldChapter.Id, oldChapter.Name, newChapter.Name,
         oldChapter.SeqNo, newChapter.SeqNo, oldChapter.CourseId, newChapter.CourseId);
     AdminOperationLogBll.AddAdminOperationLog(AdminUserId, log);
     // 跳转列表
     string url = string.Format("/Chapter/List/{0}", oldChapter.CourseId);
     return JsonHelper.GetJsonResult(_OK, "更新章节成功", url);
 }
Ejemplo n.º 8
0
 public int AddChapter(Chapter chapter)
 {
     var chptrs = from chptr in _dbContext.Chapters
                  where chptr.CourseId == chapter.CourseId && chptr.SeqNo >= chapter.SeqNo
                  select chptr;
     Chapter first = chptrs.FirstOrDefault();
     if (first != null && first.SeqNo == chapter.SeqNo)
     {
         foreach (var chptr in chptrs)
         {
             chptr.SeqNo += 1L;
             _dbContext.Entry(chptr).State = EntityState.Modified;
         }
     }
     _dbContext.Entry(chapter).State = EntityState.Added;
     return _dbContext.SaveChanges();
 }