public void Initialize() { List <JobPrediction> jobPredictions = JobPrediction.Enum1(); List <JobPredictionViewModel> jobPredictionViewModels = new List <JobPredictionViewModel>(); foreach (JobPrediction jobPrediction in jobPredictions) { if (jobPredictionViewModels.Any(x => x.PhaseName == jobPrediction.Phase)) { JobPredictionViewModel jobPredictionViewModel = jobPredictionViewModels.First(x => x.PhaseName == jobPrediction.Phase); //jobPredictionViewModel.AmountsPerMonth.Add(new ObservableCollection<string>(jobPrediction.Amount)); for (int index = 0; index < jobPrediction.Months.Count; index++) { if (jobPredictionViewModel.AmountsPerMonth[index] == null) { jobPredictionViewModel.AmountsPerMonth.Add(new ObservableCollection <string>() { jobPrediction.Amount[index] }); } else { jobPredictionViewModel.AmountsPerMonth[index].Add(jobPrediction.Amount[index]); } } } else { jobPredictionViewModels.Add(new JobPredictionViewModel(jobPrediction)); } } JobPredictions = new ObservableCollection <JobPredictionViewModel>(jobPredictionViewModels); }
public JobPredictionViewModel(JobPrediction jobPrediction) { _phaseName = jobPrediction.Phase; _date = jobPrediction.Date; _percentComplete = jobPrediction.PercentComplete; _headers = jobPrediction.Months; ObservableCollection <string> amounts = new ObservableCollection <string>(jobPrediction.Amount); _amountsPerMonth = new List <ObservableCollection <string> >(); foreach (string amount in jobPrediction.Amount) { _amountsPerMonth.Add(new ObservableCollection <string>() { amount }); } }