コード例 #1
0
        public async Task <IActionResult> Index(string datecreate, string context, SortStateToDo sortOrder = SortStateToDo.ContextAsc, int page = 1)
        {
            int pageSize           = 3;
            IQueryable <ToDo> todo = db.ToDo.Where(u => u.LoginUser == User.Identity.Name);

            //filtr
            if (datecreate != null && Convert.ToDateTime(datecreate) != new DateTime(0).Date)
            {
                todo = todo.Where(p => p.DateCreate.Date == Convert.ToDateTime(datecreate).Date);
            }
            if (!String.IsNullOrEmpty(context))
            {
                todo = todo.Where(p => p.Context.Contains(context));
            }

            //sort
            todo = sortOrder switch
            {
                SortStateToDo.ContextDesc => todo.OrderByDescending(s => s.Context),
                SortStateToDo.DateCreateAsc => todo.OrderBy(s => s.DateCreate),
                SortStateToDo.DateCreateDesc => todo.OrderByDescending(s => s.DateCreate),
                _ => todo.OrderBy(s => s.Context),
            };

            //page
            var count = await todo.CountAsync();

            IQueryable <ToDo> items = todo.Skip((page - 1) * pageSize).Take(pageSize);
            var dateForFilter       = db.ToDo.Select(p => p.DateCreate.Date.ToString("dd/MM/yyyy")).Distinct().ToList();

            //create view
            IndexViewModel indexViewModel = new IndexViewModel
            {
                todo            = items,
                PageViewModel   = new PageViewModel(count, page, pageSize),
                FilterViewModel = new FilterViewModel(dateForFilter, datecreate, context),
                SortViewModel   = new SortViewModel(sortOrder)
            };

            return(View(indexViewModel));
        }
コード例 #2
0
ファイル: SortViewModel.cs プロジェクト: Karchage/ToDoApp
        }                                          // Значение выбранного свойства

        public SortViewModel(SortStateToDo sortOrder)
        {
            ContextSort    = sortOrder == SortStateToDo.ContextAsc ? SortStateToDo.ContextDesc : SortStateToDo.ContextAsc;
            DateCreateSort = sortOrder == SortStateToDo.DateCreateAsc ? SortStateToDo.DateCreateDesc : SortStateToDo.DateCreateAsc;
            Current        = sortOrder;
        }