Example #1
0
 public SortUsersViewModel(SortStateUser sortOrder)
 {
     NameSort     = sortOrder == SortStateUser.NameAsc ? SortStateUser.NameDesc : SortStateUser.NameAsc;
     EmailSort    = sortOrder == SortStateUser.EmailAsc ? SortStateUser.EmailDesc : SortStateUser.EmailAsc;
     SexSort      = sortOrder == SortStateUser.SexAsc ? SortStateUser.SexDesc : SortStateUser.SexAsc;
     BirthdaySort = sortOrder == SortStateUser.BirthdayAsc ? SortStateUser.BirthdayDesc : SortStateUser.BirthdayAsc;
     Current      = sortOrder;
 }
Example #2
0
        // GET: LifeJoys
        public async Task <IActionResult> Index(string searchString, SortStateUser sortOrder = SortStateUser.NameAsc)
        {
            var applicationDbContext = _context.LifeJoys.Include(l => l.ApplicationUsers);

            var joys = from j in _context.LifeJoys
                       select j;

            if (!String.IsNullOrEmpty(searchString))
            {
                joys = joys.Where(s => s.LifeJoyExpl.Contains(searchString));
            }

            ViewData["NameSort"] = sortOrder == SortStateUser.NameAsc ? SortStateUser.NameDesc : SortStateUser.NameAsc;
            ViewData["DateSort"] = sortOrder == SortStateUser.DateAsc ? SortStateUser.DateDesc : SortStateUser.DateAsc;

            switch (sortOrder)
            {
            case SortStateUser.NameDesc:
                joys = joys.OrderByDescending(s => s.LifeJoyExpl);
                break;

            case SortStateUser.DateAsc:
                joys = joys.OrderBy(s => s.JobDate);
                break;

            case SortStateUser.DateDesc:
                joys = joys.OrderByDescending(s => s.JobDate);
                break;

            default:
                joys = joys.OrderBy(s => s.LifeJoyExpl);
                break;
            }

            return(View(await joys.ToListAsync()));
        }
Example #3
0
        public IActionResult Index(string searchString,
                                   int page = 1,
                                   SortStateUser sortOrder = SortStateUser.NameAsc,
                                   int pageSize            = 3)
        {
            IQueryable <User> source = _userManager.Users;

            if (!String.IsNullOrEmpty(searchString))
            {
                source = source.Where(p => p.UserName.Contains(searchString) || p.Email.Contains(searchString));
            }

            switch (sortOrder)
            {
            case SortStateUser.NameDesc:
                source = source.OrderByDescending(s => s.UserName);
                break;

            case SortStateUser.BirthdayAsc:
                source = source.OrderBy(s => s.Birthday);
                break;

            case SortStateUser.BirthdayDesc:
                source = source.OrderByDescending(s => s.Birthday);
                break;

            case SortStateUser.EmailAsc:
                source = source.OrderBy(s => s.Email);
                break;

            case SortStateUser.EmailDesc:
                source = source.OrderByDescending(s => s.Email);
                break;

            case SortStateUser.SexAsc:
                source = source.OrderBy(s => s.Sex);
                break;

            case SortStateUser.SexDesc:
                source = source.OrderByDescending(s => s.Sex);
                break;

            default:
                source = source.OrderBy(s => s.UserName);
                break;
            }

            var count = source.Count();
            var items = source.Skip((page - 1) * pageSize).Take(pageSize).ProjectTo <UserViewModel>(_mapper.ConfigurationProvider).ToList();

            PageViewModel pageViewModel = new PageViewModel(count, page, pageSize);

            UserListViewModel userListViewModel = new UserListViewModel();

            userListViewModel.UserViewModel        = items;
            userListViewModel.PageViewModel        = pageViewModel;
            userListViewModel.SortUsersViewModel   = new SortUsersViewModel(sortOrder);
            userListViewModel.FilterUsersViewModel = new FilterUsersViewModel(searchString);

            return(View(userListViewModel));
        }