public virtual async Task Execute() { using (var unitOfWork = _unitOfWorkManager.Begin()) { var allWorkspacesFromAPI = powerBIProvider.GetAllWorkspaces(); DeActiveDeletedWorkspaces(allWorkspacesFromAPI); foreach (var apiWorkspace in allWorkspacesFromAPI) { DeActiveDeletedReports(apiWorkspace.Id); DeActiveDeletedDashboards(apiWorkspace.Id); var projectWorkspace = GetProjectOfWorkspace(apiWorkspace); if (projectWorkspace != null) { List <Reports.Report> reports = GetReportsOfWorkspace(projectWorkspace); await powerBIProvider.CheckMasterReportsWithProjectsWorkspaces(projectWorkspace, reports); } Workspace workspaceObject = await GetWorkSpaceDB(apiWorkspace); if (workspaceObject != null) { if (workspaceObject.Name != apiWorkspace.Name) { workspaceObject.Name = apiWorkspace.Name; workspaceRepository.Update(workspaceObject); } InsertReportsAndDashboards(apiWorkspace, workspaceObject, true); } else { workspaceObject = new Workspace { WorkspaceId = apiWorkspace.Id, Name = apiWorkspace.Name, IsActive = true }; workspaceRepository.Insert(workspaceObject); InsertReportsAndDashboards(apiWorkspace, workspaceObject, false); } } unitOfWork.Complete(); } }