예제 #1
0
        public async Task <DisplayedTasks> ReceiveTasksAsync(QueryOptions options)
        {
            if (options.SelectedCategoryId == null)
            {
                options.SelectedCategoryId = dbCategories.Min(c => c.Id);
            }
            IQueryable <TaskItem> processedTasks = dbTasks;

            QueryProcessing queryProcessing = new QueryProcessing(options);

            processedTasks = queryProcessing.SearchTasks(processedTasks);
            processedTasks = queryProcessing.FilterTasks(processedTasks);

            if (options.SelectedCategoryId == 0)
            {
                return(await GetFoundTasksAsync(queryProcessing));
            }
            else if (options.SelectedCategoryId == (long)CategoryFilterType.Starred)
            {
                return(await GetStarredTasksAsync(processedTasks, queryProcessing));
            }
            else if (options.SelectedCategoryId == (long)CategoryFilterType.Today)
            {
                return(await GetTodayTasksAsync(processedTasks, queryProcessing));
            }
            else if (options.SelectedCategoryId == (long)CategoryFilterType.Week)
            {
                return(await GetWeekTasksAsync(processedTasks, queryProcessing));
            }
            else
            {
                return(await GetTasksAsync(processedTasks, queryProcessing));
            }
        }
예제 #2
0
        private async Task <DisplayedTasks> GetFoundTasksAsync(QueryProcessing queryProcessing)
        {
            IQueryable <TaskItem> processedTasks = queryProcessing.SearchTasks(dbTasks);

            processedTasks = processedTasks.Where(t => t.EffectiveDate == null);
            processedTasks = queryProcessing.SortTasks(processedTasks);

            long minId = dbCategories.Min(c => c.Id);
            IQueryable <Category> secondCategories             = dbCategories.Where(c => c.Id > minId).OrderBy(c => c.Name);
            Dictionary <string, IEnumerable <TaskItem> > tasks = await dbCategories
                                                                 .Where(c => c.Id == minId)
                                                                 .Concat(secondCategories).GroupJoin(
                processedTasks,
                c => c.Id,
                t => t.CategoryId,
                (c, ct) => new { c.Name, ct })
                                                                 .Where(a => a.ct.Count() > 0)
                                                                 .ToDictionaryAsync(anonymous => anonymous.Name, anonymous => anonymous.ct);

            return(new DisplayedTasks
            {
                Found = tasks
            });
        }