public static List<Profile> CreateListOfProfiles(MainViewModel viewModel) { List<Profile> profiles = new List<Profile>(); for (int index = 0; index < viewModel.Tasks.Count; index++) { var taskList = viewModel.Tasks[index]; List<Task> taskModels = new List<Task>(); foreach (var task in taskList) { Task taskModel = new Task() { Description = task.TaskDetails, Name = task.TaskName, Category = task.Category}; taskModels.Add(taskModel); } Profile profile = new Profile() { Id = viewModel.Names[index].Id, Name = viewModel.Names[index].PersonName, Tasks = taskModels }; profiles.Add(profile); } return profiles; }
public static MainViewModel CreateViewModel(List<Profile> profiles) { var taskListsVM = new ObservableCollection<ObservableCollection<ItemViewModel>>(); var namesVM = new ObservableCollection<ItemNameViewModel>(); foreach (var profile in profiles) { var taskList = profile.Tasks; var taskListVM = new ObservableCollection<ItemViewModel>(); foreach (var task in taskList) { var taskVM = new ItemViewModel() { TaskDetails = task.Description, TaskName = task.Name, Category = task.Category}; taskListVM.Add(taskVM); } taskListsVM.Add(taskListVM); var nameVM = new ItemNameViewModel() { PersonName = profile.Name, Id = profile.Id }; namesVM.Add(nameVM); } var model = new MainViewModel() {IsDataLoaded = false, Names = namesVM, Tasks = taskListsVM}; return model; }