コード例 #1
0
        private void DeleteItem(int ind)
        {
            var progressList = new List <WorkoutData>();

            for (int i = 0; i < progress.Length; i++)
            {
                if (i != ind)
                {
                    progressList.Add(progress[i]);
                }
            }
            Workouts.Remove(Workouts[ind]);
            progress = progressList.ToArray();
            foreach (var workout in Workouts)
            {
                foreach (var item in workout.ExerciseDetails)
                {
                    if (planDict.ContainsKey(item.Id))
                    {
                        if (planDict[item.Id].Item1 == ind)
                        {
                            planDict.Remove(item.Id);
                        }
                        if (planDict[item.Id].Item1 > ind)
                        {
                            planDict[item.Id] = new Tuple <int, int>(planDict[item.Id].Item1 - 1, planDict[item.Id].Item2);
                        }
                    }
                }
            }
            UpdateProgress();
            DataManager.SaveProgress(progress);
        }
コード例 #2
0
        public WorkoutManagerViewModel()
        {
            Add = new Command(async() =>
            {
                await navigation_.PushAsync(new WorkoutCreation());
                await RefreshList();
            });

            Edit = new Command <object>(async w =>
            {
                var workout = Workouts.First(e => e == w);
                await workout.Edit(database_);
                Workouts.Remove(workout);
                Workouts.Add(await database_.GetWorkout(workout.Id, workout.WorkoutType));
            });

            Delete = new Command <object>(async w =>
            {
                var workout = (IWorkout)w;
                if (await AskQuestion("Delete " + workout.Title + " is permament"))
                {
                    Workouts.Remove(workout);
                    await workout.RemoveFrom(database_);
                }
            });
        }
コード例 #3
0
        private async Task DeleteWorkout()
        {
            if (_selectedWorkout == null)
            {
                return;
            }
            if (await _pageService.DisplayAlert("Delete workout", "You are about to permamently delete a workout!", "Delete", "Cancel"))
            {
                await _workoutStore.DeleteWorkout(_selectedWorkout);

                Workouts.Remove(_selectedWorkout);
                _selectedWorkout = null;
            }
        }
コード例 #4
0
        public void DeleteWorkout(object sender)
        {
            if (sender == null || !(sender is Button button))
            {
                return;
            }
            if (!(button.DataContext is Models.Workout.Workout workout))
            {
                return;
            }

            using var db = new AppDbContext();
            db.Workouts.Remove(workout);
            db.SaveChanges();

            Workouts.Remove(workout);
        }