private void LoadWebsiteReports() { IsRefreshed = false; var newReportList = new List <ReportViewModel>(); if (CurrentWebsite != null) { if (ReportsCollectionView != null) { ReportsCollectionView.OfType <ReportViewModel>().ToList().ForEach(rpt => { rpt.IsSelected = false; }); } var quarters = GetAvailableQuarters().ToList(); foreach (var dataset in CurrentWebsite.Datasets) { var datasetTypeName = dataset.Dataset.ContentType.Name; var datasets = CurrentWebsite.Datasets .Where(x => x.Dataset.ContentType.Name == datasetTypeName) //.DistinctBy(x => x.Dataset.ReportingYear) .Select(x => Tuple.Create(x.Dataset.ReportingYear, x.Dataset.ContentType.Name)) .ToList(); foreach (var reportModel in ManageViewModel.AllAvailableReports) { if (!datasetTypeName.In(reportModel.Datasets)) { continue; } reportModel.IsTrendingEnabled = reportModel.IsTrendingReport && (quarters.Count(q => reportModel.Datasets.Contains(q.Name)) > 1 || (datasets != null && datasets.DistinctBy(x => x.Item1).Count() > 1)); reportModel.IsValueChanged -= reportModel_IsValueChanged; var websiteReport = CurrentWebsite.IsPersisted && CurrentWebsite.Reports != null?CurrentWebsite.Reports.FirstOrDefault(x => x.Report.Id == reportModel.Report.Id) : null; if (websiteReport != null) { reportModel.WebsitesForDisplay = websiteReport.AssociatedWebsites; reportModel.IsQuarterlyTrendingEnabled = websiteReport.IsQuarterlyTrendingEnabled; // reportModel.IsSelected = CurrentWebsite.Reports != null && CurrentWebsite.Reports.Any(x => x.Report.Id == reportModel.Report.Id); } reportModel.WebsiteAudiences = CurrentWebsite.Audiences.ToList(); //if (websiteReport == null && CurrentWebsite.Reports != null && _newDataSetsAdded) //{ reportModel.IsSelected = (CurrentWebsite.Reports != null && CurrentWebsite.Reports.Any(x => x.Report.Id == reportModel.Report.Id)) || CurrentWebsite.Reports != null && !CurrentWebsite.Reports.Any() && reportModel.IsDefault && reportModel.Report.Audiences.Any(a => a.In(CurrentWebsite.Audiences)); //} reportModel.IsValueChanged += reportModel_IsValueChanged; if (reportModel.IsTrendingEnabled) { var period = GetTrendingYears(datasets, reportModel, quarters); reportModel.Years = period.Item1; reportModel.SelectedDefaultYear = period.Item2; var minYear = reportModel.Years.Min(x => x.Year); var expandedYear = reportModel.Years.FirstOrDefault(x => x.Year == minYear); if (expandedYear != null) { expandedYear.IsExpanded = true; } } if (newReportList.Contains(reportModel)) { continue; } if (!reportModel.IsTrendingReport || (reportModel.IsTrendingReport && reportModel.IsTrendingEnabled)) { newReportList.Add(reportModel); } } } } ReportsCollectionView = newReportList.ToMultiSelectListCollectionView(); if (ReportsCollectionView == null || ReportsCollectionView.Count == 0) { return; } OnClosePreview(); OnCloseTrending(); // ReportsCollectionView.MoveCurrentToFirst(); // SelectedReport = ReportsCollectionView.CurrentItem as ReportViewModel; SelectedReportsCount = ReportsCollectionView.SelectedItems.Count; IsRefreshed = true; }
public void LoadDataAndGetWebsiteSelectedReports(string selectedCategory = null) { // First filter reports by selected Datasets, category when applicable LoadData(); // Now set default selection by audience type if selected already. if (CurrentWebsite != null) { if (CurrentWebsite.Reports != null && CurrentWebsite.Reports.Any()) { foreach (var websiteReport in CurrentWebsite.Reports.ToList()) { var selectedReport = ReportsCollectionView.OfType <ReportViewModel>().SingleOrDefault(m => m.Report.Id == websiteReport.Report.Id); if (selectedReport == null) { continue; } selectedReport.WebsitesForDisplay = websiteReport.AssociatedWebsites; //selectedReport.Websites = !string.IsNullOrEmpty(websiteReport.AssociatedWebsites) // ? websiteReport.AssociatedWebsites.Split(',').ToObservableCollection() // : new ObservableCollection<string>(); selectedReport.IsSelected = true; if (selectedReport.Years != null) { var defaultOrYear = selectedReport.Years.FirstOrDefault(x => x.Year == websiteReport.DefaultSelectedYear); selectedReport.SelectedDefaultYear = defaultOrYear != null ? defaultOrYear.Year : null; selectedReport.Years.ForEach(x => x.IsSelected = false); websiteReport.SelectedYears.ForEach(year => { var temp = selectedReport.Years.FirstOrDefault(r => r.Year == year.Year); if (temp != null) { temp.IsSelected = true; } }); } } //foreach(var unselectedReport in ReportsCollectionView.OfType<ReportViewModel>().Where(m => !m.IsSelected).ToList()) //{ // var audienceArgs = new List<string>(); // unselectedReport.Report.Audiences.ForEach(a => audienceArgs.Add(a.ToString())); // if (!unselectedReport.IsDefault) continue; // audienceArgs.ToList() // .ForEach(audience => unselectedReport.IsSelected = CurrentWebsite.Audiences.Any(a => a.ToString().EqualsIgnoreCase(audience))); //} // IsAllSelected = ReportsCollectionView.OfType<ReportViewModel>().Count() == CurrentWebsite.Reports.Count; } else { //IsAllSelected = true; foreach (var reportModel in ReportsCollectionView.OfType <ReportViewModel>().ToList()) { var audienceArgs = new List <string>(); reportModel.Report.Audiences.ForEach(a => audienceArgs.Add(a.ToString())); if (!reportModel.IsDefault) { continue; } foreach (var audience in audienceArgs) { reportModel.IsSelected = CurrentWebsite.Audiences.Any(a => a.ToString().EqualsIgnoreCase(audience)); } } } } else { // IsAllSelected = true; foreach (var reportModel in ReportsCollectionView.OfType <ReportViewModel>().ToList()) { reportModel.IsSelected = reportModel.IsDefault; } } ReportsCollectionView.Filter = CompositeFilter; //IsAllSelected = IsAllSelectedCheck(); RaisePropertyChanged(() => IsAllSelected); }