public async Task <ResponseEntity> removeUserFromTask(TaskUser model, string token)
        {
            var task = _taskRepository.GetSingleByConditionAsync("taskId", model.taskId).Result;

            if (task == null)
            {
                return(new ResponseEntity(StatusCodeConstants.NOT_FOUND, "task is not found!", MessageConstants.MESSAGE_ERROR_404));
            }

            UserJira user = _userService.getUserByToken(token).Result;
            Project  pro  = _projectRepository.GetSingleByConditionAsync("id", task.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>("taskId", model.taskId));
            columns.Add(new KeyValuePair <string, dynamic>("userId", model.userId));
            var            taskUser = _taskUserRepository.GetMultiByListConditionAndAsync(columns).Result;
            List <dynamic> lstId    = new List <dynamic>();

            foreach (var item in taskUser)
            {
                lstId.Add(item.id);
            }

            await _taskUserRepository.DeleteByIdAsync(lstId);

            return(new ResponseEntity(StatusCodeConstants.OK, "remove user from task successfully!", 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));
            }
        }