private void RemoveResources() { PublishedProject publishedProject = null; DraftProject draftProject; List <DraftProjectResource> draftProjectResourceresList = new List <DraftProjectResource>(); LV_Projects.InvokeIfRequired(s => publishedProject = (PublishedProject)s.SelectedItems[0].Tag); LV_ProjectResources.InvokeIfRequired(s => { ListView.SelectedListViewItemCollection selectedItems = s.SelectedItems; draftProjectResourceresList.AddRange(selectedItems.Cast <ListViewItem>().Select(selectedItem => (DraftProjectResource)selectedItem.Tag)); }); if (draftProjectResourceresList.Any()) { draftProject = publishedProject.IsCheckedOut ? publishedProject.Draft : publishedProject.CheckOut(); draftProjectResourceresList.ForEach(r => { Log.WriteVerbose(new SourceInfo(), TB_Status, "Removing Resource:{0} from Project:{1}.", r.Name, publishedProject.Draft.Name); draftProject.ProjectResources.Remove(r); }); QueueJob queueJob = draftProject.Update(); Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeRemoveProjectResources, "Waiting for the Project Update job to complete."); CsomHelper.ExecuteAndWait(queueJob, TB_Status); } Log.WriteVerbose(new SourceInfo(), TB_Status, _bgeRemoveProjectResources, "Refreshing Project resources."); GetDraftTeamForSelectedProject(); }
private void GetDraftTeamForSelectedProject() { PublishedProject project = null; LV_Projects.InvokeIfRequired(s => project = s.SelectedItems[0].Tag as PublishedProject); LV_ProjectResources.InvokeIfRequired(s => s.Items.Clear()); IEnumerable <DraftProjectResource> resourceList = ProjContext.LoadQuery(project.Draft.ProjectResources); ProjContext.ExecuteQuery(); DraftProjectResource[] draftProjectResources = resourceList.ToArray(); foreach (ListViewItem lvi in draftProjectResources.Select(res => new ListViewItem(res.Name) { Tag = res })) { LV_ProjectResources.InvokeIfRequired(s => s.Items.Add(lvi)); } LV_ProjectResources.InvokeIfRequired(s => s.Columns[0].Text = $"Project Resources({draftProjectResources.Length})"); }