コード例 #1
0
        public JsonResult GetListQuestionByPart(int examId, int accountId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                if (!_examRepository.ExamExist(examId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.GROUP_NOT_FOUND)));
                }

                if (!ModelState.IsValid)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND)));
                }

                //This is get all account exam of the exam by id exam
                List <AccountExamEntity> listAccountExamEntity = _accountExamRepository.GetListAccountExamByExamId(examId);

                List <AccountFinishExam> accountFinishExams = new List <AccountFinishExam>();

                foreach (var item in listAccountExamEntity)
                {
                    if (item.IsStatus.Equals("Finish"))
                    {
                        AccountEntity     accountEntity     = _accountRepository.GetAccountById(item.AccountId);
                        AccountFinishExam accountFinishExam = new AccountFinishExam();
                        accountFinishExam.accountId = accountEntity.AccountId;
                        accountFinishExam.name      = accountEntity.FullName;
                        accountFinishExams.Add(accountFinishExam);
                    }
                }

                accountFinishExams = accountFinishExams.Where(a => a.accountId != accountId).ToList();

                return(Json(accountFinishExams));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #2
0
        public JsonResult CreateQuestion([FromBody] List <QuestionDto> questions)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                int examId = 0;

                if (questions == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notInformationQuestion));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_INFORMATION_QUESTION)));
                }

                foreach (var question in questions)
                {
                    if (!_examRepository.ExamExist(question.examId))
                    {
                        Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.examNotFound));
                        return(Json(MessageResult.GetMessage(MessageType.EXAM_NOT_FOUND)));
                    }

                    examId = question.examId;
                }


                if (!ModelState.IsValid)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND)));
                }
                foreach (var question in questions)
                {
                    //Map data enter from the form to question entity
                    var partExam = Mapper.Map <PPT.Database.Entities.QuestionEntity>(question);

                    //This is query insert question
                    _questionRepository.CreatePart(partExam, question.examId);
                }

                List <AccountExamEntity> accountExams = _accountExamRepository.GetListAccountExamByExamId(examId);

                foreach (var item in accountExams)
                {
                    item.IsStatus = "Do Exam";
                    _accountExamRepository.Save();
                }

                if (!_questionRepository.Save())
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.badRequest));
                    return(Json(MessageResult.GetMessage(MessageType.BAD_REQUEST)));
                }

                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.createdQuestion));
                return(Json(MessageResult.GetMessage(MessageType.CREATED_QUESTION)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }