public async Task <ResponseEntity> addUserProject(UserProject project, string token = "")
        {
            UserJira user = _userService.getUserByToken(token).Result;
            Project  pro  = _projectRepository.GetSingleByConditionAsync("id", project.projectId).Result;

            if (pro == null)
            {
                return(new ResponseEntity(StatusCodeConstants.NOT_FOUND, "Project is not found!", MessageConstants.MESSAGE_ERROR_404));
            }
            if (pro.creator != user.id)
            {
                return(new ResponseEntity(StatusCodeConstants.FORBIDDEN, "User is unthorization!", MessageConstants.MESSAGE_ERROR_403));
            }
            List <KeyValuePair <string, dynamic> > columns = new List <KeyValuePair <string, dynamic> >();

            columns.Add(new KeyValuePair <string, dynamic>("projectId", project.projectId));
            columns.Add(new KeyValuePair <string, dynamic>("userId", project.userId));


            IEnumerable <Project_User> lstProjectUser = _projectUserRepository.GetMultiByListConditionAndAsync(columns).Result;

            if (lstProjectUser.Count() > 0)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "User already exists in the project!", MessageConstants.MESSAGE_ERROR_500));
            }
            Project_User model = new Project_User();

            model.userId    = project.userId;
            model.projectId = project.projectId;
            model.deleted   = false;
            model.alias     = project.userId + "_" + project.projectId;
            await _projectUserRepository.InsertAsync(model);

            return(new ResponseEntity(StatusCodeConstants.OK, "has added the user to the project !", MessageConstants.MESSAGE_SUCCESS_200));
        }
Beispiel #2
0
        public async Task <ResponseEntity> deleteUser(int id)
        {
            try
            {
                var userEdit = _useJiraRepository.GetSingleByConditionAsync("id", id).Result;
                if (userEdit == null)
                {
                    return(new ResponseEntity(StatusCodeConstants.NOT_FOUND, MessageConstants.DELETE_ERROR, MessageConstants.MESSAGE_ERROR_404));
                }
                List <KeyValuePair <string, dynamic> > columns = new List <KeyValuePair <string, dynamic> >();
                columns.Add(new KeyValuePair <string, dynamic>("userId", userEdit.id));
                var lstUserProject = _project_userRepository.GetMultiByListConditionAndAsync(columns).Result;



                var lstTask = _taskUserRepository.GetMultiByListConditionAndAsync(columns).Result;



                var lstComment = _taskUserRepository.GetMultiByListConditionAndAsync(columns).Result;

                List <KeyValuePair <string, dynamic> > columns1 = new List <KeyValuePair <string, dynamic> >();
                columns1.Add(new KeyValuePair <string, dynamic>("creator", userEdit.id));
                var project = _projectRepository.GetMultiByListConditionAndAsync(columns1).Result;

                if (project.Count() > 0)
                {
                    return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Người dùng đã tạo project không thể xoá được !", MessageConstants.MESSAGE_ERROR_400));
                }


                List <dynamic> lstResult = new List <dynamic>();
                foreach (var item in lstTask)
                {
                    lstResult.Add(item.id);
                }
                await _taskUserRepository.DeleteByIdAsync(lstResult);

                List <dynamic> lstResult1 = new List <dynamic>();

                foreach (var item in lstUserProject)
                {
                    lstResult1.Add(item.id);
                }
                await _project_userRepository.DeleteByIdAsync(lstResult1);



                List <dynamic> lstResult2 = new List <dynamic>();

                foreach (var item in lstComment)
                {
                    lstResult2.Add(item.id);
                }
                await _commentRepository.DeleteByIdAsync(lstResult2);



                List <dynamic> lstId = new List <dynamic>();
                lstId.Add(id);



                await _useJiraRepository.DeleteByIdAsync(lstId);

                return(new ResponseEntity(StatusCodeConstants.OK, MessageConstants.DELETE_SUCCESS, MessageConstants.MESSAGE_SUCCESS_200));
            }catch (Exception err)
            {
                return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, MessageConstants.DELETE_ERROR, MessageConstants.MESSAGE_ERROR_400));
            }
        }