Example #1
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)));
            }
        }
Example #2
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)));
            }
        }