public async Task <ResponseEntity> removeUSerFromProject(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; List <dynamic> lstId = new List <dynamic>(); foreach (var item in lstProjectUser) { lstId.Add(item.id); } await _projectUserRepository.DeleteByIdAsync(lstId); return(new ResponseEntity(StatusCodeConstants.OK, "remove user from project successfully !", MessageConstants.MESSAGE_SUCCESS_200)); }
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)); } }