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

            try
            {
                //Check id exam exist in the database
                if (!_examRepository.ExamExist(examId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.examNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.EXAM_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 information of exam by Id
                ExamEntity examEntity = _examRepository.GetExamById(examId);

                return(Json(examEntity));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #2
0
        public JsonResult GetInformationGroup(int groupId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id group exist in the database
                if (!_groupRepository.GroupExist(groupId))
                {
                    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 information of group by Id
                GroupEntity groupEntity = _groupRepository.GetGroupById(groupId);

                return(Json(groupEntity));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #3
0
        public JsonResult GetInformationAccount(int id)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id account exist in the database
                if (!_accountRepository.AccountExists(id))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_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 information of account
                AccountEntity account = _accountRepository.GetAccountById(id);

                return(Json(account));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #4
0
        public JsonResult GetGroupList(int accountId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

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

                //get group list by owner Id
                List <GroupOwnerEntity> groupEntities = _groupRepository.GetGroupListByOwnerId(accountId);

                List <GroupMemberEntity> groupMembers = _groupMemberRepository.GetGroupMemberByAccountId(accountId);

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

                // Create new list result to get data
                List <GroupListResult> groupListResult = new List <GroupListResult>();

                foreach (var groupOwner in groupEntities)
                {
                    GroupEntity     group     = _groupRepository.GetGroupById(groupOwner.GroupId);
                    GroupListResult groupList = new GroupListResult();
                    groupList.groupId      = groupOwner.GroupId.ToString("0000");
                    groupList.groupOwnerId = groupOwner.GroupOwnerId;
                    groupList.ownerGroupId = groupOwner.AccountId;
                    groupList.groupName    = group.Name;
                    groupList.description  = group.Description;
                    groupListResult.Add(groupList);
                }

                foreach (var groupMember in groupMembers)
                {
                    GroupEntity     group     = _groupRepository.GetGroupById(groupMember.GroupId);
                    GroupListResult groupList = new GroupListResult();
                    groupList.groupId      = groupMember.GroupId.ToString("0000");
                    groupList.groupOwnerId = groupMember.GroupMemberId;
                    groupList.ownerGroupId = groupMember.AccountId;
                    groupList.groupName    = group.Name;
                    groupList.description  = group.Description;
                    groupListResult.Add(groupList);
                }

                return(Json(groupListResult.OrderByDescending(a => a.groupId)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #5
0
        public JsonResult GetAllAccounts()
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

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

                //This is get all information of account
                List <AccountEntity> listAccounts = _accountRepository.GetAllAccounts();

                List <LoginResult> listAccount = new List <LoginResult>();

                foreach (var item in listAccounts)
                {
                    IEnumerable <AccountRoleEntity> listRole = _accountRepository.GetAccountRoles(item.AccountId);
                    LoginResult account = new LoginResult();
                    account.accountId   = item.AccountId;
                    account.email       = item.Email;
                    account.fullName    = item.FullName;
                    account.phoneNumber = item.Phone;
                    account.address     = item.Address;
                    var listRoles = new List <string>();

                    List <RoleEntity> roles = new List <RoleEntity>();

                    //Browser the elements of list role
                    foreach (var poi in listRole)
                    {
                        RoleEntity roleEntity = _accountRepository.GetRole(poi.RoleId);
                        roles.Add(roleEntity);
                    }

                    foreach (var role in roles)
                    {
                        listRoles.Add(role.NameRole);
                    }

                    account.Roles = listRoles;

                    listAccount.Add(account);
                }

                return(Json(listAccount));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #6
0
        public JsonResult DeleteQuestion(int examId, int questionId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id exam exist in the database
                if (!_examRepository.ExamExist(examId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.examNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.EXAM_NOT_FOUND)));
                }

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

                QuestionEntity question = null;
                //This is get all information of the exam by examId
                List <ExamQuestionEntity> examQuestionEntity = _examQuestionRepository.getListQuestions(examId);

                foreach (var examQuestion in examQuestionEntity)
                {
                    if (examQuestion.QuestionId == questionId)
                    {
                        question = _questionRepository.getQuestionInformation(questionId);
                    }
                }

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

                _questionRepository.DeleteQuestion(question.QuestionId);

                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.questionDeleted));
                return(Json(MessageResult.GetMessage(MessageType.QUESTION_DELETED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #7
0
        public JsonResult UpdateAccount([FromBody] AccountForUpdateDto account)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id account exist in the database
                if (!_accountRepository.AccountExists(account.accountId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

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

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

                //This is get all information of account
                var accountEntity = _accountRepository.GetAccountById(account.accountId);

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

                //Map data enter from the form to account entity
                Mapper.Map(account, accountEntity);

                if (!_accountRepository.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.accountUpdated));
                return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_UPDATED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #8
0
        public JsonResult CreatePointOfInterest([FromBody] AccountForCreationDto account)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

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

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

                //Check email enter from the form exist in the database
                if (!_accountRepository.EmailExist(account.Email))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.emailExist));
                    return(Json(MessageResult.GetMessage(MessageType.EMAIL_EXIST)));
                }

                //This is send email to vertified account
                SendGmail.SendVertified(account.Email);

                //Hash new password
                account.Password = PasswordUtil.CreateMD5(account.Password);

                //Map data enter from the form to account entity
                var finalAccount = Mapper.Map <PPT.Database.Entities.AccountEntity>(account);

                //This is query insert account
                _accountRepository.Register(finalAccount);

                if (!_accountRepository.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.registerSuccess));
                return(Json(MessageResult.GetMessage(MessageType.REGISTER_SUCCESS)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #9
0
        public JsonResult UpdateInformationExam([FromBody] ExamForCreationDto exam)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id group exist in the database
                if (!_examRepository.ExamExist(exam.ExamId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.examNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.EXAM_NOT_FOUND)));
                }

                //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.badRequest));
                    return(Json(MessageResult.GetMessage(MessageType.BAD_REQUEST)));
                }

                //This is get all information of group
                var examEntity = _examRepository.GetExamById(exam.ExamId);

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

                //Map data enter from the form to group entity
                Mapper.Map(exam, examEntity);

                if (!_examRepository.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.examUpdated));
                return(Json(MessageResult.GetMessage(MessageType.EXAM_UPDATED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #10
0
        public JsonResult UpdateAccount([FromBody] GroupForUpdateDto group)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id group exist in the database
                if (!_groupRepository.GroupExist(group.groupId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.GROUP_NOT_FOUND)));
                }

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

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

                //This is get all information of group
                var groupEntity = _groupRepository.GetGroupById(group.groupId);

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

                //Map data enter from the form to group entity
                Mapper.Map(group, groupEntity);

                if (!_groupRepository.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.groupUpdated));
                return(Json(MessageResult.GetMessage(MessageType.GROUP_UPDATED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #11
0
        public JsonResult GetInformationGroup(int examId, int questionId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id exam exist in the database
                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)));
                }
                QuestionEntity question = null;
                //This is get all information of the exam by examId
                List <ExamQuestionEntity> examQuestionEntity = _examQuestionRepository.getListQuestions(examId);

                QuestionListResult questionListResult = new QuestionListResult();
                foreach (var examQuestion in examQuestionEntity)
                {
                    if (examQuestion.QuestionId == questionId)
                    {
                        question = _questionRepository.getQuestionInformation(questionId);
                        break;
                    }
                }

                questionListResult.questionId     = question.QuestionId;
                questionListResult.questionNumber = question.QuestionNumber;
                questionListResult.part           = question.Part;
                questionListResult.image          = question.Image;
                questionListResult.fileMp3        = question.FileMp3;
                questionListResult.questionName   = question.QuestionName;
                questionListResult.A             = question.A;
                questionListResult.B             = question.B;
                questionListResult.C             = question.C;
                questionListResult.D             = question.D;
                questionListResult.correctAnswer = question.CorrectAnswer;
                questionListResult.team          = question.Team;

                return(Json(questionListResult));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #12
0
        public JsonResult ForgotPassword(string email)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

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

                //Check email enter from the form not exist in the database
                if (_accountRepository.EmailExist(email))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.emailNotExist));
                    return(Json(MessageResult.GetMessage(MessageType.EMAIL_NOT_EXIST)));
                }

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

                //Check email enter from the form exist in the database
                if (!_accountRepository.EmailExist(email))
                {
                    //This is send new password through email
                    string code = SendGmail.ForgotPassword(email);

                    AccountEntity accountEntity = _accountRepository.GetAccountByEmail(email);
                    //This is update new password
                    accountEntity.Password = PasswordUtil.CreateMD5(code);
                }

                if (!_accountRepository.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.sendPassword));
                return(Json(MessageResult.GetMessage(MessageType.SEND_PASSWORD)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #13
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)));
            }
        }
コード例 #14
0
        public JsonResult GetMemberList(int groupId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

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

                List <GroupMemberEntity> memberEntities = _groupRepository.GetMemberListByGroupId(groupId);

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

                List <MemberListResult> memberListResult = new List <MemberListResult>();

                foreach (var members in memberEntities)
                {
                    MemberListResult memberList = new MemberListResult();
                    memberList.groupMemberId = members.GroupMemberId;
                    memberList.groupId       = members.GroupId;
                    memberList.accountId     = members.AccountId;
                    AccountEntity accountEntity = _accountRepository.GetAccountById(members.AccountId);
                    memberList.email       = accountEntity.Email;
                    memberList.fullName    = accountEntity.FullName;
                    memberList.address     = accountEntity.Address;
                    memberList.phoneNumber = accountEntity.Phone;
                    memberListResult.Add(memberList);
                }

                return(Json(memberListResult));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #15
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)));
            }
        }
コード例 #16
0
        public JsonResult CreatePointOfInterest([FromBody] CommentDto comment)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

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

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

                GroupMemberEntity groupMemberEntity = _groupMemberRepository.GetGroupMemberByGroupIdAndAccountId(comment.groupId, comment.accountId);

                //Map data enter from the form to comment entity
                var comments = Mapper.Map <PPT.Database.Entities.CommentEntity>(comment);
                comments.GroupMemberId   = groupMemberEntity.GroupMemberId;
                comments.DateTimeComment = DateTime.Now;
                comments.AccountId       = comment.accountId;

                _commentRepository.CreateComment(comments);

                if (!_commentRepository.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.commentSuccess));
                return(Json(MessageResult.GetMessage(MessageType.COMMENTSUCCESS)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #17
0
        public JsonResult SearchMemberInGroup(string name)
        {
            //get method name
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check value enter id group
                if (name == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.valueIsNull));
                    return(Json(MessageResult.GetMessage(MessageType.VALUEISNULL)));
                }

                List <SearchResult> listResult = new List <SearchResult>();
                //get all member with contain name from form body
                List <AccountEntity> memberEntities = _accountRepository.SearchMemberByName(name);
                if (memberEntities != null)
                {
                    //add member into listResult
                    foreach (var groupMember in memberEntities)
                    {
                        AccountEntity account = _accountRepository.GetAccountById(groupMember.AccountId);
                        SearchResult  result  = new SearchResult();
                        result.accountId = account.AccountId;
                        result.fullName  = account.FullName;
                        listResult.Add(result);
                    }
                }
                //list member with that name is null, it's will show message error
                else
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notInformationAccount));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_INFORMATION_MEMBER)));
                }

                return(Json(listResult.Take(10)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #18
0
        public JsonResult GetInformationAccount(int accountId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id account exist in the database
                if (!_accountRepository.AccountExists(accountId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

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

                //Get list all history by id account
                List <HistoryEntity> list = _historyRepository.getHistoryByAccount(accountId);

                List <HistoryResult> listResult = new List <HistoryResult>();

                foreach (var history in list)
                {
                    HistoryResult result = new HistoryResult();
                    ExamEntity    exam   = _examRepository.GetExamById(history.ExamId);
                    GroupEntity   group  = _groupRepository.GetGroupById(history.GroupId);
                    result.nameExam  = exam.Name;
                    result.nameGroup = group.Name;

                    listResult.Add(result);
                }

                return(Json(listResult));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #19
0
        public JsonResult CreationGroup([FromBody] GroupForCreationDto group)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                AccountEntity account = _accountRepository.GetAccountById(group.accountId); //get account from AccountController stored data user logged in
                if (group == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notInformationGroup));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_INFORMATION_GROUP)));
                }

                //This is get current day
                group.CreatedDate = DateTime.Now;

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

                var finalGroup = Mapper.Map <PPT.Database.Entities.GroupEntity>(group);

                //This is query insert account
                _groupRepository.CreationGroup(finalGroup, account);

                if (!_groupRepository.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.groupCreated));
                return(Json(MessageResult.GetMessage(MessageType.GROUP_CREATED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #20
0
        public JsonResult GetInformationGroup(int examId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id exam exist in the database
                if (!_examRepository.ExamExist(examId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.examNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.EXAM_NOT_FOUND)));
                }

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

                List <CommentEntity> listComment = _commentRepository.GetCommentByExamId(examId);

                List <CommentResult> listResult = new List <CommentResult>();

                foreach (var comment in listComment)
                {
                    CommentResult result  = new CommentResult();
                    AccountEntity account = _accountRepository.GetAccountById(comment.AccountId);
                    result.name     = account.FullName;
                    result.dateTime = comment.DateTimeComment;
                    result.content  = comment.Content;

                    listResult.Add(result);
                }

                return(Json(listResult));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #21
0
        public JsonResult DeleteMember(int groupId, int accountId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id group exist in the database
                if (!_accountRepository.AccountExists(accountId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

                //This is get all member of group by id acount
                var memberEntity = _groupMemberRepository.GetGroupMemberByGroupIdAndAccountId(groupId, accountId);

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

                //This is query to delete member
                _groupRepository.DeleteMember(memberEntity);

                if (!_groupRepository.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.memberDeleted));
                return(Json(MessageResult.GetMessage(MessageType.MEMBER_DELETED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #22
0
        public JsonResult DeleteGroup(int groupId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id group exist in the database
                if (!_groupRepository.GroupExist(groupId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.GROUP_NOT_FOUND)));
                }

                //This is get all information of group by Id
                var groupEntity = _groupRepository.GetGroupById(groupId);

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

                //This is query to delete group
                _groupRepository.DeleteGroup(groupEntity);

                if (!_groupRepository.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.groupDeleted));
                return(Json(MessageResult.GetMessage(MessageType.GROUP_DELETED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #23
0
        public JsonResult DeleteAccount(int id)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id account exist in the database
                if (!_accountRepository.AccountExists(id))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

                //This is get all information of account
                var accountEntity = _accountRepository.GetAccountById(id);

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

                //This is query to delete account
                _accountRepository.DeleteAccount(accountEntity);

                if (!_accountRepository.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.accountDeleted));
                return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_DELETED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #24
0
        public JsonResult Login([FromBody] AccountDto account)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                if (account == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notEnterEmail));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_ENTER_EMAIL)));
                }

                //This is hash password
                string hastPwd = PasswordUtil.CreateMD5(account.password);

                //Query account following email and password
                AccountEntity accountEntity = _accountRepository.LoginAccount(account.email, hastPwd);

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

                //This is get list role of account entity
                IEnumerable <AccountRoleEntity> listRole = _accountRepository.GetAccountRoles(accountEntity.AccountId);

                //This is set data for login result
                LoginResult result = new LoginResult();


                HttpContext.Session.SetInt32("accountId", account.accountId);
                result.accountId   = accountEntity.AccountId;
                result.email       = accountEntity.Email;
                result.password    = accountEntity.Password;
                result.fullName    = accountEntity.FullName;
                result.phoneNumber = accountEntity.Phone;
                result.address     = accountEntity.Address;
                var a = HttpContext.Session.Get("accountId");
                result.Session = a;
                var listRoles = new List <string>();

                List <RoleEntity> roles = new List <RoleEntity>();

                //Browser the elements of list role
                foreach (var poi in listRole)
                {
                    RoleEntity roleEntity = _accountRepository.GetRole(poi.RoleId);
                    roles.Add(roleEntity);
                }

                foreach (var item in roles)
                {
                    listRoles.Add(item.NameRole);
                }

                result.Roles = listRoles;
                return(Json(result));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #25
0
        public JsonResult AddMember([FromBody] AccountGroup account, int groupId)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                if (account == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notEnterEmail));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_ENTER_EMAIL)));
                }

                GroupMemberEntity groupMemberEntity = _groupMemberRepository.GetGroupMemberByGroupIdAndAccountId(groupId, account.accountID);

                if (groupMemberEntity != null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupMemberExist));
                    return(Json(MessageResult.GetMessage(MessageType.GROUP_MEMBER_EXIST)));
                }

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

                // get group by group Id in line 52
                GroupEntity groupEntity = _groupRepository.GetGroupById(groupId);
                if (groupEntity == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.groupNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.GROUP_NOT_FOUND)));
                }

                // get account by email. Email was input from the form
                AccountEntity accountEntity = _accountRepository.GetAccountById(account.accountID);
                if (accountEntity == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

                //This is query add member into this group
                _groupRepository.AddMemberIntoGroup(groupEntity, accountEntity);

                List <ExamEntity> listExamEntity = _examRepository.GetListExamByGroupId(groupId);

                foreach (var item in listExamEntity)
                {
                    AccountExamEntity accountExamEntity = new AccountExamEntity();
                    accountExamEntity.AccountId = accountEntity.AccountId;
                    accountExamEntity.ExamId    = item.ExamId;
                    accountExamEntity.IsStatus  = "Do Exam";
                    _accountExamRepository.CreateAccountExam(accountExamEntity);
                }

                if (!_groupRepository.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.memberAdded));
                return(Json(MessageResult.GetMessage(MessageType.MEMBER_ADDED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #26
0
        public JsonResult UpdateAccountPatch([FromBody] ChangingPassword account)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id account exist in the database
                if (!_accountRepository.AccountExists(account.accountId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

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

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

                var oldPass = PasswordUtil.CreateMD5(account.oldPassword);

                //This is get all information of account
                var accountEntity = _accountRepository.GetAccountById(account.accountId);

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

                //This is check old password
                if (accountEntity.Password != oldPass)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.oldPasswordNotTrue));
                    return(Json(MessageResult.GetMessage(MessageType.OLD_PASSWORD_NOT_TRUE)));
                }

                //This is update new password
                accountEntity.Password = PasswordUtil.CreateMD5(account.newPassword);

                if (!_accountRepository.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.accountUpdated));
                return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_UPDATED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #27
0
        public JsonResult GetListQuestionByPart(int examId, string part, 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 questions of the exam by id exam
                List <ExamQuestionEntity> examQuestionEntity = _examQuestionRepository.getListQuestions(examId);

                List <QuestionEntity> listQuestionEntities = new List <QuestionEntity>();
                foreach (var examQuestion in examQuestionEntity)
                {
                    // Get all informations of the question by questionId and save it in the list
                    QuestionEntity questionEntity = _questionRepository.getQuestionInformation(examQuestion.QuestionId);
                    listQuestionEntities.Add(questionEntity);
                }

                List <QuestionListResult> questionLists      = new List <QuestionListResult>();
                List <AnswerUserEntity>   answerUserEntities = _answerUserRepository.GetAnswerUserEntities(accountId);

                List <AnswerUserResult> answerUserResults = new List <AnswerUserResult>();
                foreach (var examQuestion in listQuestionEntities)
                {
                    QuestionListResult q = new QuestionListResult();
                    foreach (var item in answerUserEntities)
                    {
                        if (item.QuestionId == examQuestion.QuestionId)
                        {
                            q.answerUser = item.AnswerKey;
                            break;
                        }
                    }
                    if (examQuestion.Part.Equals(part))
                    {
                        q.questionId     = examQuestion.QuestionId;
                        q.questionNumber = examQuestion.QuestionNumber;
                        q.part           = examQuestion.Part;
                        q.image          = examQuestion.Image;
                        q.fileMp3        = examQuestion.FileMp3;
                        q.questionName   = examQuestion.QuestionName;
                        q.A             = examQuestion.A;
                        q.B             = examQuestion.B;
                        q.C             = examQuestion.C;
                        q.D             = examQuestion.D;
                        q.correctAnswer = examQuestion.CorrectAnswer;
                        q.team          = examQuestion.Team;

                        questionLists.Add(q);
                    }
                }

                return(Json(questionLists.OrderBy(q => q.questionNumber)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #28
0
        public JsonResult GetListQuestion(int accountId, int examId, int page)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                if (!_accountRepository.AccountExists(accountId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

                //Check id exam exist in the database
                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 questions of the exam by id exam
                List <ExamQuestionEntity> examQuestionEntity = _examQuestionRepository.getListQuestions(examId);
                List <AnswerUserEntity>   answerUsers        = _answerUserRepository.GetAnswerUserEntities(accountId);

                List <QuestionEntity> listQuestionEntities = new List <QuestionEntity>();
                foreach (var examQuestion in examQuestionEntity)
                {
                    // Get all informations of the question by questionId and save it in the list
                    QuestionEntity questionEntity = _questionRepository.getQuestionInformation(examQuestion.QuestionId);
                    listQuestionEntities.Add(questionEntity);
                }

                List <QuestionListResult> questionLists = new List <QuestionListResult>();
                foreach (var item in listQuestionEntities)
                {
                    QuestionListResult q = new QuestionListResult();
                    q.questionId    = item.QuestionId;
                    q.part          = item.Part;
                    q.image         = item.Image;
                    q.fileMp3       = item.FileMp3;
                    q.questionName  = item.QuestionName;
                    q.A             = item.A;
                    q.B             = item.B;
                    q.C             = item.C;
                    q.D             = item.D;
                    q.correctAnswer = item.CorrectAnswer;
                    q.team          = item.Team;
                    foreach (var answer in answerUsers)
                    {
                        if (q.questionId == answer.QuestionId)
                        {
                            q.answerUser = answer.AnswerKey;
                        }
                    }
                    questionLists.Add(q);
                }

                List <QuestionListResult> pagging = Pagging.GetQuestions(page, questionLists);

                return(Json(pagging));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #29
0
        public JsonResult UpdateInformationQuestion([FromBody] QuestionUpdate question)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id exam exist in the database
                if (!_examRepository.ExamExist(question.examId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.examNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.EXAM_NOT_FOUND)));
                }

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

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

                QuestionEntity questionEntity = null;
                //This is get all information of the exam by examId
                List <ExamQuestionEntity> examQuestionEntity = _examQuestionRepository.getListQuestions(question.examId);

                foreach (var examQuestion in examQuestionEntity)
                {
                    if (examQuestion.QuestionId == question.questionId)
                    {
                        questionEntity = _questionRepository.getQuestionInformation(question.questionId);
                    }
                }

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

                //Map data enter from the form to question entity
                Mapper.Map(question, questionEntity);

                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.questionUpdated));
                return(Json(MessageResult.GetMessage(MessageType.QUESTION_UPDATED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
コード例 #30
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)));
            }
        }