Exemplo n.º 1
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();
            }
        }