public async Task <List <ListProject> > FindAllToListAsync(int?accessLevel, int?employeeId) { var obj = from project in _context.Project join client in _context.Client on project.Client_Id equals client.Id join manager in _context.Employee on project.Manager_Id equals manager.Id into Managers from employee in Managers.DefaultIfEmpty() join managerProject in _context.Employee on project.Project_Manager_Id equals managerProject.Id into ManagersProjects from managersProjects in ManagersProjects.DefaultIfEmpty() select new ListProject { Id = project.Id, Project = project.Project_Name == null ? "" : project.Project_Name, Client = client.Name == null ? "" : client.Name, Status = project.Active == null ? "" : project.Active.ToString(), CostCenter = project.Cost_Center_Id == null ? 0 : project.Cost_Center_Id, Manager_Id = employee.Id == null ? 0 : employee.Id, Project_Manager_Id = managersProjects.Id == null ? 0 : managersProjects.Id, Manager = employee.Name == null ? "" : employee.Name, Project_Manager = managersProjects.Name == null ? "" : managersProjects.Name, AcessLevel = employee.Access_LevelId == null ? 0 : employee.Access_LevelId }; if (accessLevel == 2) { obj = obj.Where(x => x.Project_Manager_Id == employeeId); } return(await obj .OrderBy(x => x.Project) .ToListAsync()); //return await _context.Project // .OrderBy(x => x.Project_Name).ToListAsync(); }