Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
        public ActionResult UpdateChapter()
        {
            log.Debug(Constant.DEBUG_START);

            string idString = ApiQueryUtil.QueryArgByPost("id");
            string name = ApiQueryUtil.QueryArgByPost("name");

            ServiceInvokeDTO result = null;
            try
            {
                Chapter chapter = new Chapter();
                chapter.ID = Convert.ToInt32(idString);
                chapter.Name = name;

                result = itemDataService.UpdateChapter(chapter);
            }
            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);
        }
Exemplo n.º 3
0
        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);
            }
            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);
        }
Exemplo n.º 4
0
        /// <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;
        }
Exemplo n.º 5
0
 /// <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);
     }
 }
Exemplo n.º 6
0
        /// <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;
        }