Ejemplo n.º 1
0
        public JsonResult GetListExam(int accountId, int groupId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check value enter id group
                if (accountId == 0 || groupId == 0)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.emailAndPasswordWrong));
                    return(Json(MessageResult.GetMessage(MessageType.EMAIL_AND_PASSWORD_WRONG)));
                }

                List <AccountExamEntity> listAccountExams = _accountExamRepository.GetAccountExamByAccountId(accountId);

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

                List <ExamResult> examResults = new List <ExamResult>();
                GroupOwnerEntity  ownerEntity = _groupOwnerRepository.GetGroupOwnerByGroupId(groupId);
                foreach (var accountExam in listAccountExams)
                {
                    ExamEntity examEntity = _examRepository.GetExamById(accountExam.ExamId);
                    if (examEntity.GroupId == groupId)
                    {
                        ExamResult result = new ExamResult();
                        result.examId = accountExam.ExamId;
                        result.name   = examEntity.Name;
                        result.status = accountExam.IsStatus;
                        examResults.Add(result);
                    }
                }

                ExamResultHasOwner examResultHasOwner = new ExamResultHasOwner();
                examResultHasOwner.ownerId     = ownerEntity.AccountId;
                examResultHasOwner.examResults = examResults;
                return(Json(examResultHasOwner));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
Ejemplo n.º 2
0
        public JsonResult CreateExam([FromBody] ExamForCreationDto exam)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check value enter from the form
                if (exam == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notInformationExam));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_INFORMATION_EXAM)));
                }

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

                GroupOwnerEntity groupOwner = _groupOwnerRepository.GetGroupOwnerByGroupId(exam.GroupId);
                //Map data enter from the form to exam entity
                var finalExam = Mapper.Map <PPT.Database.Entities.ExamEntity>(exam);

                //This is query insert exam
                _examRepository.CreateExam(finalExam);

                if (!_examRepository.Save())
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.badRequest));

                    return(Json(MessageResult.GetMessage(MessageType.BAD_REQUEST)));
                }
                GroupEntity groupEntity = _groupRepository.GetGroupByExam(finalExam);

                List <GroupMemberEntity> listGroupMembers = _groupMemberRepository.GetGroupMemberByGroupId(groupEntity.GroupId);
                if (listGroupMembers.Count() > 0)
                {
                    AccountExamEntity accountExamEntity1 = new AccountExamEntity();
                    accountExamEntity1.Exam      = finalExam;
                    accountExamEntity1.AccountId = groupOwner.AccountId;
                    accountExamEntity1.ExamId    = finalExam.ExamId;
                    accountExamEntity1.IsStatus  = "Empty";
                    _accountExamRepository.CreateAccountExam(accountExamEntity1);
                    _accountExamRepository.Save();
                    foreach (var item in listGroupMembers)
                    {
                        AccountExamEntity accountExamEntity = new AccountExamEntity();
                        accountExamEntity.Exam      = finalExam;
                        accountExamEntity.AccountId = item.AccountId;
                        accountExamEntity.Account   = item.Account;
                        accountExamEntity.ExamId    = finalExam.ExamId;
                        accountExamEntity.IsStatus  = "Empty";
                        _accountExamRepository.CreateAccountExam(accountExamEntity);
                        _accountExamRepository.Save();
                    }
                }
                else
                {
                    AccountExamEntity accountExamEntity = new AccountExamEntity();
                    accountExamEntity.Exam      = finalExam;
                    accountExamEntity.AccountId = groupOwner.AccountId;
                    accountExamEntity.ExamId    = finalExam.ExamId;
                    accountExamEntity.IsStatus  = "Empty";
                    _accountExamRepository.CreateAccountExam(accountExamEntity);
                    _accountExamRepository.Save();
                }
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.createdExam));
                return(Json(MessageResult.GetMessage(MessageType.CREATED_EXAM)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }