private async void BtnSave_Clicked(object sender, EventArgs e) { //_Routine.RoutineExercises = new HashSet<int>(_ViewModel.Exercises.Where(ex => ex.IsSelected) // .Select(ex => ex.Exercise.Id).ToArray()); //Was mache ich hier? Das verstehe ich momentan noch nicht: //Speichere ich über die Routine separat von den RoutineExercises? //Und die RoutineExercise über ihr eigenes Repository? Und wie mache ich das beim laden der Routine? //Oder speichere ich alles über die Routine und die Unit of Work speichert dann alles selber? _Routine.RoutineExercises = new List <RoutineExercise>(); var exerciseIds = _ViewModel.Exercises.Where(ex => ex.IsSelected).Select(ex => ex.Exercise.Id); //ToDo: Not the duty of the View foreach (var id in exerciseIds) { _Routine.RoutineExercises.Add(new RoutineExercise { Id = TrainingContext.GetRoutineExerciseId(), //IdHelper.GetRoutineExerciseId(_Uow.Routines); IdExercise = id, IdRoutine = _Routine.Id }); } RoutineRepository.Instance.Add(_Routine); //_Uow.Routines.Add(_Routine); await this.Navigation.PopModalAsync(); }
private async void BtnSave_Clicked(object sender, EventArgs e) { Routine routine; RoutineEditViewModel vm = (RoutineEditViewModel)BindingContext; routine = vm.Routine; if (routine.Title != entryTitle.Text) { routine.Title = entryTitle.Text; } routine.Description = entryDescription.Text; var choosenRoutineExercises = new List <RoutineExercise>(); var exerciseIds = vm.Exercises.Where(ex => ex.IsSelected).Select(ex => ex.Exercise.Id); //Add the selected exercises to the routine foreach (var id in exerciseIds) { choosenRoutineExercises.Add(new RoutineExercise //_Uow.Routines.Add(...) { Id = TrainingContext.GetRoutineExerciseId(), //IdHelper.GetRoutineExerciseId(_Uow.Routines); IdExercise = id, IdRoutine = routine.Id }); } //This causes a PropertyChanged event on the routine which leads to an update of the Exercises //which is the collection that is represented in the ListView routine.RoutineExercises = choosenRoutineExercises; await this.Navigation.PopModalAsync(); }