/// <summary> /// 添加章节 /// </summary> public ServiceInvokeDTO AddChapter(Chapter chapter) { log.Debug(Constant.DEBUG_START); ServiceInvokeDTO result = null; try { // 检测章节名称是否存在 Chapter dbChapter = chapterDAL.GetByName(chapter.CourseID, chapter.Name); if (dbChapter == null) { // 叠加章节序号 chapter.ChapterIndex = chapterDAL.GetLastChapterIndex(chapter.CourseID) + 1; chapterDAL.Insert(chapter); result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS); } else { result = new ServiceInvokeDTO(InvokeCode.ITEM_CHAPTER_NAME_EXIST_ERROR); } } catch (Exception ex) { log.Error(ex); throw ex; } log.Debug(Constant.DEBUG_END); return result; }
/// <summary> /// 更新章节 /// </summary> public ServiceInvokeDTO UpdateChapter(Chapter chapter) { log.Debug(Constant.DEBUG_START); ServiceInvokeDTO result = null; try { Chapter dbChapter = chapterDAL.GetByID(chapter.ID); if (dbChapter != null) { // 检测章节名称是否存在 Chapter chapterWithName = chapterDAL.GetByName(dbChapter.CourseID, chapter.Name); if (chapterWithName != null && chapterWithName.ID != chapter.ID) { result = new ServiceInvokeDTO(InvokeCode.ITEM_CHAPTER_NAME_EXIST_ERROR); } else { chapter.ChapterIndex = dbChapter.ChapterIndex; chapterDAL.Update(chapter); result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS); } } else { result = new ServiceInvokeDTO(InvokeCode.SYS_OBJECT_NOT_EXIST_ERROR); } } catch (Exception ex) { log.Error(ex); throw ex; } log.Debug(Constant.DEBUG_END); return result; }
/// <summary> /// 添加实体信息,返回添加成功后的主键ID /// </summary> public int Insert(Chapter chapter) { int chapterID = 0; const string sql = @"INSERT INTO Chapter(CourseID, ChapterIndex, Name) VALUES (@CourseID, @ChapterIndex, @Name); SELECT LAST_INSERT_ID();"; using (DbConnection connection = ConnectionManager.OpenConnection) { chapterID = connection.Query<int>(sql, chapter).SingleOrDefault<int>(); } return chapterID; }
/// <summary> /// 更新实体信息 /// </summary> public void Update(Chapter chapter) { const string sql = @"UPDATE Chapter SET ChapterIndex = @ChapterIndex, Name= @Name WHERE IsDeleted = 0 AND ID = @ID"; using (DbConnection connection = ConnectionManager.OpenConnection) { connection.Execute(sql, chapter); } }
public ActionResult AddChapter() { log.Debug(Constant.DEBUG_START); string name = ApiQueryUtil.QueryArgByPost("name"); ServiceInvokeDTO result = null; try { Chapter chapter = new Chapter(); chapter.CourseID = (Session[Constant.SESSION_KEY_COURSE] as Course).ID; chapter.Name = name; result = itemDataService.AddChapter(chapter); // Write admin do record. if (result != null && result.Code == InvokeCode.SYS_INVOKE_SUCCESS) { AgencyAdminDTO currentAdmin = Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO; AdminDoRecord doRecord = new AdminDoRecord(); doRecord.AdminID = currentAdmin.ID; doRecord.AdminName = currentAdmin.ChineseName; doRecord.DoTime = DateTime.Now; doRecord.DoName = DoActionType.AddChapter.GetDescription(); doRecord.DoContent = string.Format("新章节名称:{0}", name); doRecord.Remark = string.Empty; recordDataService.AddAdminDoRecord(doRecord); } } catch (Exception ex) { log.Error(ex); result = new ServiceInvokeDTO(InvokeCode.SYS_INNER_ERROR); } string json = JsonConvert.SerializeObject(result, Formatting.Indented, Constant.TIME_CONVERTER); log.Debug(Constant.DEBUG_END); return Content(json, Constant.JSON_MIME_TYPE); }