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);
            }
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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;
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
 /// <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);
 }