public static TaskDateViewModelParameter Instance( TaskListItemViewModel taskList, TaskItemViewModel task, TaskNotificationDateType dateType, bool sendUpdatedMsg = false) { return(new TaskDateViewModelParameter(taskList, task, dateType, sendUpdatedMsg)); }
private TaskDateViewModelParameter( TaskListItemViewModel taskList, TaskItemViewModel task, TaskNotificationDateType dateType, bool sendUpdatedMsg) { TaskList = taskList ?? throw new ArgumentNullException(nameof(taskList)); Task = task ?? throw new ArgumentNullException(nameof(task)); DateType = dateType; SendUpdateMsg = sendUpdatedMsg; }
private async Task RemoveTaskNotificationDateAsync(TaskNotificationDateType dateType) { string message = dateType == TaskNotificationDateType.TO_BE_COMPLETED_DATE ? "completition" : "reminder"; bool isConfirmed = await _dialogService.ShowConfirmationDialogAsync( "Confirm", $"Are you sure you want to remove this task's {message} date ?", "Yes", "No"); if (!isConfirmed) { return; } ShowTaskProgressRing = true; if (!CurrentTask.IsNew) { if (dateType == TaskNotificationDateType.REMINDER_DATE && int.TryParse(CurrentTask.RemindOnGUID, out int id)) { _notificationService.RemoveScheduledNotification(id); } var response = await _dataService .TaskService .RemoveNotificationDate(CurrentTask.Id, dateType); if (!response.Succeed) { await _dialogService.ShowMessageDialogAsync( "Error", $"Could not remove the {message} date of {CurrentTask.Title}"); } CurrentTask = _mapper.Map <TaskItemViewModel>(response.Result); } else { switch (dateType) { case TaskNotificationDateType.TO_BE_COMPLETED_DATE: CurrentTask.ToBeCompletedOn = null; break; case TaskNotificationDateType.REMINDER_DATE: CurrentTask.RemindOn = null; break; } } _messenger.Send(CurrentTask.TaskID, $"{MessageType.TASK_SAVED}"); ShowTaskProgressRing = false; }
public async Task <ResponseDto <GoogleTask> > AddNotificationDate(string taskID, TaskNotificationDateType dateType, DateTimeOffset remindOn, string remindOnGuid) { return(await Task.Run(async() => { _logger.Information($"AddReminderNotificationDate: Trying to add a reminder date for taskID = {taskID}"); var response = new ResponseDto <GoogleTask> { Message = string.Empty, Succeed = false }; using (var context = new MiraiNotesContext()) { try { var taskToUpdate = await context .Tasks .FirstOrDefaultAsync(t => t.GoogleTaskID == taskID); if (taskToUpdate == null) { response.Message = $"Could not find the task with taskID = {taskID}"; _logger.Warning($"AddReminderNotificationDate: Could not find a task with taskID = {taskID}"); return response; } switch (dateType) { case TaskNotificationDateType.TO_BE_COMPLETED_DATE: taskToUpdate.ToBeCompletedOn = remindOn; break; case TaskNotificationDateType.REMINDER_DATE: if (string.IsNullOrEmpty(remindOnGuid)) { throw new ArgumentNullException(nameof(remindOnGuid), "If the date type is reminder, then you must provide a valid guid"); } taskToUpdate.RemindOn = remindOn; taskToUpdate.RemindOnGUID = remindOnGuid; break; default: throw new ArgumentOutOfRangeException(nameof(dateType), dateType, "Provided google task date type does not exists"); } response.Succeed = await context.SaveChangesAsync() > 0; response.Result = taskToUpdate; _logger.Information("AddReminderNotificationDate: Completed successfully"); } catch (Exception e) { _logger.Error(e, "AddReminderNotificationDate: An unknown error occurred"); response.Message = GetExceptionMessage(e); } } return response; }).ConfigureAwait(false)); }
public async Task <ResponseDto <GoogleTask> > RemoveNotificationDate(int taskID, TaskNotificationDateType dateType) { return(await Task.Run(async() => { string dateToRemoveType = dateType == TaskNotificationDateType.REMINDER_DATE ? "reminder" : "completition"; _logger.Information($"RemoveDate: Trying to remove the {dateToRemoveType} date of taskID = {taskID}"); var response = new ResponseDto <GoogleTask> { Message = string.Empty, Succeed = false }; using (var context = new MiraiNotesContext()) { try { var taskToUpdate = await context .Tasks .FirstOrDefaultAsync(t => t.ID == taskID); if (taskToUpdate == null) { response.Message = $"Could not find the task with taskID = {taskID} to remove its {dateToRemoveType} date"; _logger.Warning($"RemoveDate: Could not find a task with taskID = {taskID}"); return response; } switch (dateType) { case TaskNotificationDateType.TO_BE_COMPLETED_DATE: taskToUpdate.ToBeCompletedOn = null; break; case TaskNotificationDateType.REMINDER_DATE: taskToUpdate.RemindOn = null; taskToUpdate.RemindOnGUID = null; break; default: throw new ArgumentOutOfRangeException(nameof(dateType), dateType, "Provided google task date type does not exists"); } context.Tasks.Update(taskToUpdate); response.Succeed = await context.SaveChangesAsync() > 0; response.Result = taskToUpdate; _logger.Information("RemoveDate: Completed successfully"); } catch (Exception e) { _logger.Error(e, "RemoveDate: An unknown error occurred"); response.Message = GetExceptionMessage(e); } } return response; }).ConfigureAwait(false)); }