Beispiel #1
0
        private async Task Save()
        {
            Name = Name.TrimStart().TrimEnd();

            if (string.IsNullOrEmpty(Name))
            {
                await Application.Current.MainPage.DisplayAlert("", StringResources.ForgotRoutineName, StringResources.OK);
            }
            else if (!DaysOfWeek.GetHasADayBeenSelected(Routine.Days))
            {
                await Application.Current.MainPage.DisplayAlert("", StringResources.ForgotRoutineDays, StringResources.OK);
            }
            else if (HasNoHabit)
            {
                await Application.Current.MainPage.DisplayAlert("", StringResources.ForgotHabit, StringResources.OK);
            }
            else
            {
                if (Routine.Id == 0)
                {
                    Routine.Index = App.RoutineService.Routines.Count;
                }
                var id = App.RoutineService.SaveRoutine(Routine);

                foreach (var habit in Habits)
                {
                    habit.RoutineId = id;
                }
                App.HabitService.SaveHabits(Habits);

                foreach (var habit in HabitsForDelete)
                {
                    if (habit.Id != 0)
                    {
                        App.HabitService.DeleteHabit(habit.Id);
                    }
                }

                await ClosePopup();

                var diffString = CreateTimeToString.CreateTimeRemainingString(Routine.NextAlarmTime);
                DependencyService.Get <IToastService>().Show(diffString);
            }
        }
Beispiel #2
0
        public void OnIsActiveChanged()
        {
            try
            {
                if (IsInitFinished)
                {
                    App.RoutineService.SaveRoutineAtLocal(this);

                    if (IsActive)
                    {
                        var diffString = CreateTimeToString.CreateTimeRemainingString(NextAlarmTime);
                        DependencyService.Get <IToastService>().Show(diffString);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"{e.Message}");
                Console.WriteLine($"{e.StackTrace}");
                Console.WriteLine($"{e.Data}");
                Console.WriteLine("OnIsActiveChangedException");
            }
        }