Exemple #1
0
        /// <summary>
        /// 添加老师
        /// </summary>
        public ServiceInvokeDTO AddTeacher(Teacher teacher)
        {
            log.Debug(Constant.DEBUG_START);
            ServiceInvokeDTO result = null;
            try
            {
                // Check user name
                Teacher dbTeacher = teacherDAL.GetByUserName(teacher.UserName);
                if (dbTeacher == null)
                {
                    teacher.Password = SecurityUtil.MD5(teacher.Password + Constant.TEACHER_SALT_KEY);
                    teacherDAL.Insert(teacher);
                    result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS);
                }
                else
                {
                    result = new ServiceInvokeDTO(InvokeCode.ACCOUNT_TEACHER_ACCOUNT_EXIST_ERROR);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
            log.Debug(Constant.DEBUG_END);

            return result;
        }
Exemple #2
0
        public ActionResult AddTeacher()
        {
            log.Debug(Constant.DEBUG_START);

            string chineseName = ApiQueryUtil.QueryArgByPost("chinese_name");
            string userName = ApiQueryUtil.QueryArgByPost("user_name");
            string password = ApiQueryUtil.QueryArgByPost("password");
            string isCanMarkPaperString = ApiQueryUtil.QueryArgByPost("is_can_mark_paper");

            ServiceInvokeDTO result = null;
            try
            {
                Teacher teacher = new Teacher();
                teacher.ChineseName = chineseName;
                teacher.UserName = userName;
                teacher.Password = password;
                teacher.Level = TeacherLevel.ItemAdmin;
                teacher.IsCanMarkPaper = Convert.ToInt32(isCanMarkPaperString);

                result = accountDataService.AddTeacher(teacher);
            }
            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);
        }
Exemple #3
0
        /// <summary>
        /// 添加实体信息,返回添加成功后的主键ID
        /// </summary>
        public int Insert(Teacher teacher)
        {
            int id = 0;

            const string sql = @"INSERT INTO Teacher(UserName, Password, ChineseName, Level, IsCanMarkPaper)
                               VALUES (@UserName, @Password, @ChineseName, @Level, @IsCanMarkPaper);
                               SELECT LAST_INSERT_ID();";
            using (DbConnection connection = ConnectionManager.OpenConnection)
            {
                id = connection.Query<int>(sql, teacher).SingleOrDefault<int>();
            }
            return id;
        }
Exemple #4
0
 /// <summary>
 /// 更新实体信息
 /// </summary>
 public void Update(Teacher teacher)
 {
     const string sql = @"UPDATE Teacher SET UserName= @UserName, ChineseName = @ChineseName, IsCanMarkPaper= @IsCanMarkPaper WHERE IsDeleted = 0 AND ID = @ID";
     using (DbConnection connection = ConnectionManager.OpenConnection)
     {
         connection.Execute(sql, teacher);
     }
 }
Exemple #5
0
        /// <summary>
        /// 更新老师
        /// </summary>
        public ServiceInvokeDTO UpdateTeacher(Teacher teacher)
        {
            log.Debug(Constant.DEBUG_START);
            ServiceInvokeDTO result = null;
            try
            {
                // Check user name
                Teacher dbTeacher = teacherDAL.GetByUserName(teacher.UserName);
                if (dbTeacher != null && dbTeacher.ID != teacher.ID)
                {
                    result = new ServiceInvokeDTO(InvokeCode.ACCOUNT_TEACHER_ACCOUNT_EXIST_ERROR);
                }
                else
                {
                    teacherDAL.Update(teacher);
                    result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
            log.Debug(Constant.DEBUG_END);

            return result;
        }
Exemple #6
0
        /// <summary>
        /// 读取判断题题库模板数据
        /// </summary>
        /// <param name="teacher">老师对象</param>
        /// <param name="courseID">课程主键ID</param>
        /// <param name="fileName">Excel文件路径名称</param>
        /// <param name="isFirstRowTitle">第一行是否为标题</param>
        public static List<JudgeItem> ReadJudgeTemplate(Teacher teacher, int courseID, string fileName, bool isFirstRowTitle)
        {
            List<JudgeItem> judges = new List<JudgeItem>();

            // 获取所有章节
            ServiceInvokeDTO<List<Chapter>> chaptersResult = ServiceFactory.Instance.ItemDataService.GetAgencyChapters(courseID);
            if (chaptersResult.Code == InvokeCode.SYS_INVOKE_SUCCESS && chaptersResult.Data != null && chaptersResult.Data.Count > 0)
            {
                List<Chapter> chapters = chaptersResult.Data;

                using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                {
                    // 默认读取第一张表
                    IWorkbook workBook = WorkbookFactory.Create(fs);
                    ISheet sheet = workBook.GetSheetAt(0);

                    int startRowIndex = 0;
                    if (isFirstRowTitle && sheet.LastRowNum >= 1)
                    {
                        startRowIndex = 1;
                    }

                    for (int index = startRowIndex; index <= sheet.LastRowNum; index++)
                    {
                        IRow row = sheet.GetRow(index);
                        if (row != null)
                        {
                            // 所属章节
                            ICell chapterCell = row.GetCell(1); if (chapterCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }
                            string chapterName = chapterCell.ToString().Trim();
                            int chapterID = 0;
                            foreach (var chapter in chapters)
                            {
                                if (chapterName.Equals(chapter.Name))
                                {
                                    chapterID = chapter.ID;
                                    break;
                                }
                            }
                            if (chapterID == 0)
                            {
                                throw new ArgumentException(CHAPTER_ID_ERROR);
                            }

                            ICell titleCell = row.GetCell(2); if (titleCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }

                            // 答案
                            ICell amswerCell = row.GetCell(3); if (amswerCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }
                            string answerString = amswerCell.ToString().Trim().ToUpper();
                            if (!answerString.Equals(ANSWER_CORRECT) && !answerString.Equals(ANSWER_ERROR))
                            {
                                throw new ArgumentException(ANSWER_ARG_ERROR);
                            }

                            // 试题难易度
                            ICell difficltyCell = row.GetCell(5); if (difficltyCell == null) { throw new ArgumentException(TEXT_EMPTY_ERROR); }
                            string difficltyString = difficltyCell.ToString().Trim();

                            int difficulty = 0;
                            if (int.TryParse(difficltyString, out difficulty))
                            {
                                if (difficulty < DIFFICULTY_MIN || difficulty > DIFFICULTY_MAX)
                                {
                                    throw new ArgumentException(DIFFICULTY_ARG_ERROR);
                                }
                            }
                            else
                            {
                                throw new ArgumentException(DIFFICULTY_ARG_ERROR);
                            }

                            JudgeItem judge = new JudgeItem();
                            judge.ChapterID = chapterID;
                            judge.Title = titleCell.ToString();
                            judge.Answer = answerString.Equals(ANSWER_CORRECT) ? 1 : 0;
                            judge.Annotation = row.GetCell(4) == null ? string.Empty : row.GetCell(4).ToString();
                            judge.Difficulty = difficulty;
                            judge.AddPerson = teacher.ChineseName;

                            judges.Add(judge);
                        }
                    }
                }
            }
            else
            {
                throw new ArgumentException(CHAPTER_ID_ERROR);
            }

            return judges;
        }