private void CancelAlarms(List <MedicationSpread> reminders)
        {
            if (reminders == null)
            {
                return;
            }

            AlarmHelper alarmHelper = new AlarmHelper(this);

            try
            {
                foreach (var med in reminders)
                {
                    if (med.MedicationTakeReminder != null)
                    {
                        if (med.MedicationTakeReminder.IsSet)
                        {
                            alarmHelper.CancelAlarm(med.MedicationTakeReminder.ID);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(TAG, "CancelAlarms: Exception - " + e.Message);
                if (GlobalData.ShowErrorDialog)
                {
                    ErrorDisplay.ShowErrorAlert(this, e, GetString(Resource.String.ErrorMedicationRemove), "MedicationActivity.CancelAlarms");
                }
            }
        }
Beispiel #2
0
        private async Task UpdateTasksAsync(IEnumerable <GetScheduledTaskDTO> tasks)
        {
            foreach (var task in tasks)
            {
                var dbTask = await _dataHelper.GetByIdAsync(task.Id);

                if (task.IsDeleted)
                {
                    await _dataHelper.DeleteAsync(task.Id);

                    if (dbTask != null)
                    {
                        _alarmHelper.CancelAlarm(dbTask);
                    }
                }
                else if (dbTask == null)
                {
                    var newTask = MapToEntity(task);

                    await _dataHelper.InsertAsync(newTask);

                    _alarmHelper.SetAlarm(newTask);
                }
                else
                {
                    var updatedTask = MapToEntity(task, dbTask);

                    await _dataHelper.UpdateAsync(updatedTask);

                    _alarmHelper.UpdateAlarm(updatedTask);
                }
            }
        }
Beispiel #3
0
        private async void Adapter_ItemDeleteClick(object sender, ScheduledTask e)
        {
            try
            {
                _progressBarHelper.Show();

                ToggleEmptyView();

                await _taskDataHelper.MarkAsDeletedAsync(e.Id);

                _alarmHelper.CancelAlarm(e);

                _ = SyncService.Instance.SyncAsync()
                    .ContinueWith(async t =>
                {
                    try
                    {
                        await _taskDataHelper.DeleteAsync(e.Id);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLine(LogPriority.Error, "Planner Error", ex.Message);
                    }
                }
                                  , TaskContinuationOptions.OnlyOnRanToCompletion); // warning suppressed on purpose

                _progressBarHelper.Hide();
            }
            catch (Exception ex)
            {
                Log.WriteLine(LogPriority.Error, "Planner Error", ex.Message);

                _progressBarHelper.Hide();
                _dialogHelper.ShowError(this, ex);
            }
        }