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); } }
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); } }