Beispiel #1
0
        // GET: Tasks?page=1&status=All
        public async Task <IActionResult> Index([FromQuery] int page = 1, [FromQuery] FilteredTaskStatus status = FilteredTaskStatus.All)
        {
            IPagedList <ToDoTask> tasks = await _taskService.GetPage(page, 10, status);

            TaskIndexViewModel viewModel = new TaskIndexViewModel()
            {
                Tasks          = ToMappedPagedList <ToDoTask, TaskListElementViewModel>(tasks),
                FilteredStatus = status
            };

            return(View(viewModel));
        }
Beispiel #2
0
        public Task <IPagedList <ToDoTask> > GetPage(int page, int tasksPerPage, FilteredTaskStatus filteredStatus)
        {
            IQueryable <ToDoTask> query = _ctx.Tasks.AsNoTracking();

            if (filteredStatus != FilteredTaskStatus.All)
            {
                query = query.Where(x => x.Status == filteredStatus.ToTaskStatus());
            }

            return(query.OrderBy(x => x.Status)
                   .ThenByDescending(x => x.Priority)
                   .ToPagedListAsync(page, tasksPerPage));
        }
Beispiel #3
0
        public static TaskStatus ToTaskStatus(this FilteredTaskStatus filteredStatus)
        {
            switch (filteredStatus)
            {
            case FilteredTaskStatus.Finished:
                return(TaskStatus.Finished);

            case FilteredTaskStatus.Unfinished:
                return(TaskStatus.Unfinished);

            case FilteredTaskStatus.All:
            default:
                throw new InvalidCastException("No such value in other enum");
            }
        }