Esempio n. 1
0
        public async Task OnSave()
        {
            if (await Validate())
            {
                // invalidate TotalTrophies
                App.TotalTrophies = null;

                var workout = new Workout
                {
                    WorkoutId      = this.WorkoutId,
                    ExerciseId     = Exercise.ExerciseId,
                    Created        = this.Created,
                    Notes          = this.Notes,
                    Reps           = this.Reps,
                    Weight         = _units.GetMetric(App.Settings.IsMetric, this.Weight),
                    PreviousReps   = this.PreviousReps,
                    PreviousWeight = _units.GetMetric(App.Settings.IsMetric, this.PreviousWeight),
                    TargetReps     = this.TargetReps,
                    TargetWeight   = _units.GetMetric(App.Settings.IsMetric, this.TargetWeight),
                };
                workout.Trophies = _workoutRules.GetTrophies(workout);

                var isPersisted = WorkoutId > 0;
                WorkoutId = await _workoutsRepository.SaveAsync(workout);

                _messagingService.Send(this, Messages.ItemChanged, workout);
                AppResources.WorkoutSaved.ToToast(ToastNotificationType.Success);

                if (App.Settings.RestTimerAutoStart && !isPersisted)
                {
                    await _navigationService.PopAsync();

                    if (!RestTimerItem.IsRunning)
                    {
                        var parameters = new NavigationParameters
                        {
                            { "StartImmediately", true },
                            { "RestTimerItem", RestTimerItem }
                        };
                        await _navigationService.NavigateToHierarchical <RestTimerViewModel>(parameters);
                    }
                }
                else
                {
                    await _navigationService.PopAsync();
                }
            }
        }
Esempio n. 2
0
        private async Task OnSave()
        {
            if (Validate())
            {
                var exercise = new Exercise()
                {
                    ExerciseId  = this.ExerciseId,
                    Name        = this.Name,
                    PlateWeight = _units.GetMetric(App.Settings.IsMetric, this.PlateWeight),
                    Notes       = this.Notes
                };

                var message = Messages.ItemAdded;
                if (exercise.ExerciseId > 0)
                {
                    message = Messages.ItemChanged;
                }

                ExerciseId = await _exercisesRepository.SaveAsync(exercise);

                // save routine
                foreach (var day in Days)
                {
                    day.ExerciseId = ExerciseId;
                    await _routineDaysRepository.SaveAsync(day);
                }

                _messagingService.Send(this, message, exercise);
                AppResources.ExerciseSaved.ToToast(ToastNotificationType.Success);
                await _navigationService.PopAsync();
            }
        }