Beispiel #1
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 #2
0
        private async void SaveButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (!ValidateInputs())
                {
                    return;
                }

                _progressBarHelper.Show();

                var task = new ScheduledTask()
                {
                    Id    = Guid.NewGuid(),
                    Title = titleEditText.Text,
                    Start = _startDate == default || _startTime == default
                        ? DateTime.MinValue : Utilities.ToDateTime(_startDate, _startTime),
                    End = _endDate == default || _endTime == default
                        ? DateTime.MinValue : Utilities.ToDateTime(_endDate, _endTime),
                    Importance           = SelectedImportance,
                    Note                 = noteEditText.Text,
                    Repeat               = (Frequency)_selectedRepeatIndex,
                    ApplicationUserId    = Utilities.GetUserId(),
                    ClientUpdatedOnTicks = DateTime.UtcNow.Ticks
                };

                await _taskDataHelper.InsertAsync(task);

                if (task.Start > DateTime.Now)
                {
                    _alarmHelper.SetAlarm(task);
                }

                _ = SyncService.Instance.SyncAsync(); // warning suppressed on purpose

                StartActivity(typeof(TasksActivity));

                _progressBarHelper.Hide();

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

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