public async Task Clean() { DateTime threshold = DateTime.Now; var expireds = await ( from todo in context.Todos.Include(todo => todo.Task) where todo.Expires <= threshold select todo ).ToListAsync(); foreach (var expired in expireds) { //Check for duplicates. //TODO: This duplicate check is uneccessary. Implement a timer for last rollover. var logEntry = CompletionLogEntry.FromTodo(expired); if (!context.TaskCompletionLog.Where(w => w == logEntry).Any()) { context.TaskCompletionLog.Add(logEntry); } if (!expired.Task.IsRecurring) { expired.Task.Delete(); } context.Todos.Remove(expired); } }
/// <summary> /// Remove a task from the log and add it to /// </summary> /// <param name="taskId"></param> /// <param name="emailAddress"></param> /// <param name="entryTime"></param> /// <returns></returns> public async void DeleteLogEntry(int taskId, string emailAddress, DateTime entryTime) { var task = await context.UserTasks.FindAsync(taskId); if (task == null) { return; } // Create log entry to search table var completionLogEntry = CompletionLogEntry.FromTask(task, entryTime, true); // Remove entry from Db and save changes context.TaskCompletionLog.Remove(completionLogEntry); }
public async Task Clean() { DateTime threshold = DateTime.Now; var expireds = await ( from todo in context.Todos.Include(todo => todo.Task) where todo.Expires <= threshold select todo ).ToListAsync(); foreach (var expired in expireds) { context.TaskCompletionLog.Add(CompletionLogEntry.FromTodo(expired)); if (!expired.Task.IsRecurring) { expired.Task.Delete(); } context.Todos.Remove(expired); } }
public async Task UndoCompleteTodoAsync(int todoId) { var todo = await context.Todos.Include(td => td.Task).FirstOrDefaultAsync(td => td.TaskId == todoId); if (todo == null) { return; } // Check that todo is completed if (todo.IsCompleted) {//Find and remove log entry var entry = CompletionLogEntry.FromTodo(todo); context.TaskCompletionLog.Remove(entry); //For outstanding tasks without a due date, make sure it isn't deleted at the end of the day if (!todo.Task.IsRecurring) { todo.Expires = DateTime.MaxValue; } todo.IsCompleted = false; } }
public async Task CompleteTodoAsync(int todoId) { var todo = await context.Todos.Include(td => td.Task).FirstOrDefaultAsync(td => td.TaskId == todoId); if (todo == null) { return; } if (!todo.IsCompleted) { todo.IsCompleted = true; //For outstanding tasks without a due date, get it deleted before the end of the day if (!todo.Task.IsRecurring) { todo.Expires = DateTime.Today.AddDays(1); } //Create log entry and add to log var entry = CompletionLogEntry.FromTodo(todo); await context.TaskCompletionLog.AddAsync(entry); } }
/// <summary> /// Adds a task to the lot /// </summary> /// <param name="completionLogEntry"></param> /// <returns></returns> public async Task AddLogEntryAsync(CompletionLogEntry completionLogEntry) { await context.TaskCompletionLog.AddAsync(completionLogEntry); }