private void CleanPanel()
 {
     CurrentTask = new TaskItemViewModel
     {
         Title = string.Empty,
         Notes = string.Empty
     };
     _messenger.Send(false, $"{MessageType.OPEN_PANE}");
 }
        public async Task ChangeTaskStatusAsync(TaskItemViewModel task, GoogleTaskStatus taskStatus)
        {
            string statusMessage =
                $"{(taskStatus == GoogleTaskStatus.COMPLETED ? "completed" : "incompleted")}";

            bool changeStatus = await _dialogService.ShowConfirmationDialogAsync(
                "Confirmation",
                $"Mark {task.Title} as {statusMessage}?",
                "Yes",
                "No");

            if (!changeStatus)
            {
                return;
            }

            ShowTaskProgressRing = true;

            var response = await _dataService
                           .TaskService
                           .ChangeTaskStatusAsync(task.TaskID, taskStatus);

            ShowTaskProgressRing = false;

            if (!response.Succeed)
            {
                await _dialogService.ShowMessageDialogAsync(
                    $"Error",
                    $"An error occurred while trying to mark {task.Title} as {statusMessage}. " +
                    $"Error = {response.Message}.");

                return;
            }

            task.Status      = response.Result.Status;
            task.CompletedOn = response.Result.CompletedOn;
            task.UpdatedAt   = response.Result.UpdatedAt;

            _messenger.Send(
                new Tuple <TaskItemViewModel, bool>(task, task.HasParentTask),
                $"{MessageType.TASK_STATUS_CHANGED_FROM_PANE_FRAME}");

            _messenger.Send(
                $"{task.Title} was marked as {statusMessage}.",
                $"{MessageType.SHOW_IN_APP_NOTIFICATION}");
        }
        private async Task DeleteSubTaskAsync(TaskItemViewModel subTask)
        {
            bool deleteTask = await _dialogService.ShowConfirmationDialogAsync(
                "Confirmation",
                $"Are you sure you wanna delete {subTask.Title}?",
                "Yes",
                "No");

            if (!deleteTask)
            {
                return;
            }

            if (subTask.IsNew)
            {
                CurrentTask.SubTasks?.Remove(subTask);
                return;
            }

            ShowTaskProgressRing = true;

            var deleteResponse = await _dataService
                                 .TaskService
                                 .RemoveTaskAsync(subTask.TaskID);

            if (TasksHelper.HasReminderId(subTask.RemindOnGUID, out int id))
            {
                _notificationService.RemoveScheduledNotification(id);
            }

            ShowTaskProgressRing = false;
            if (!deleteResponse.Succeed)
            {
                await _dialogService.ShowMessageDialogAsync(
                    "Error",
                    $"Coudln't delete the selected sub task. Error = {deleteResponse.Message}");

                return;
            }

            CurrentTask.SubTasks?.Remove(subTask);
            _messenger.Send(
                new KeyValuePair <string, string>(CurrentTask.TaskID, subTask.TaskID),
                $"{MessageType.SUBTASK_DELETED_FROM_PANE_FRAME}");
        }
        public async Task InitView(string taskID)
        {
            _changedProperties.Clear();
            InitialValues.Clear();

            MinDate = DateTimeOffset.Now;

            ShowTaskProgressRing = true;
            if (string.IsNullOrEmpty(taskID))
            {
                CurrentTask = new TaskItemViewModel();
            }
            else
            {
                var ta = await _dataService
                         .TaskService
                         .FirstOrDefaultAsNoTrackingAsync(x => x.GoogleTaskID == taskID);

                var sts = await _dataService
                          .TaskService
                          .GetAsNoTrackingAsync(
                    st => st.ParentTask == taskID,
                    st => st.OrderBy(x => x.Position));

                if (!ta.Succeed || !sts.Succeed)
                {
                    ShowTaskProgressRing = false;
                    await _dialogService.ShowMessageDialogAsync(
                        "Error",
                        $"An unexpected error occurred. Error = {ta.Message} {sts.Message}");

                    return;
                }

                var t = _mapper.Map <TaskItemViewModel>(ta.Result);
                t.SubTasks  = _mapper.Map <ObservableCollection <TaskItemViewModel> >(sts.Result);
                CurrentTask = t;
            }

            ShowTaskProgressRing = false;
        }
        private void OnTaskStatusChanged(TaskItemViewModel task, bool isSubTask)
        {
            TaskItemViewModel taskFound = null;

            if (!isSubTask)
            {
                taskFound = CurrentTask?.TaskID == task.TaskID ? CurrentTask : null;
            }
            else
            {
                taskFound = CurrentTask?
                            .SubTasks?
                            .FirstOrDefault(st => st.TaskID == task.TaskID);
            }

            if (taskFound == null)
            {
                return;
            }

            taskFound.CompletedOn = task.CompletedOn;
            taskFound.UpdatedAt   = task.UpdatedAt;
            taskFound.Status      = task.Status;
        }