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))); } }
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))); } }