Esempio n. 1
0
        public async Task <ActionResult> Staff(StaffListVM model, uint page)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            StaffListDTO staffList = await _staffManager.Staff(new StaffFiltersDTO
            {
                NameOrEmail = model.NameOrEmail,
                Page        = page,
                PageSize    = PageSize
            });

            model.Staff = staffList.Staff.Select(user => new StaffDataVM
            {
                Id          = user.Id,
                Email       = user.Email,
                LastName    = user.LastName,
                FirtsName   = user.FirstName,
                MiddelName  = user.MiddleName,
                PhoneNumber = user.PhoneNumber
            });
            model.PagingInfo = new PagingInfoVM
            {
                CurrentPage      = staffList.PagingInfo.CurrentPage,
                TotalItems       = staffList.PagingInfo.TotalItems,
                ItemsCurrentPage = staffList.PagingInfo.ItemsCurrentPage,
                ItemsPerPage     = staffList.PagingInfo.ItemsPerPage
            };

            return(View(model));
        }
Esempio n. 2
0
        // GET: Admin/Staffs
        public async Task <IActionResult> Index(string keyword, string orderby, string sort, int?orgId, int?page)
        {
            var vm = new StaffListVM()
            {
                PageIndex      = page == null || page <= 0 ? 1 : page.Value,
                Keyword        = keyword,
                OrganizationId = orgId,
                PageSize       = 10,
                OrderBy        = orderby,
                Sort           = sort
            };

            //var pageSize = SettingsManager.Staff.PageSize;
            var query = _context.Staffs.Include(d => d.Organization).AsNoTracking().AsQueryable();

            if (!string.IsNullOrEmpty(keyword))
            {
                query = query.Where(d => d.Name.Contains(keyword));
            }

            if (orgId > 0)
            {
                query = query.Where(d => d.OrganizationId == orgId);
            }


            var gosort = $"{orderby}_{sort}";

            query = gosort switch
            {
                "importance_asc" => query.OrderBy(s => s.Importance),
                "importance_desc" => query.OrderByDescending(s => s.Importance),
                "name_asc" => query.OrderBy(s => s.Name),
                "name_desc" => query.OrderByDescending(s => s.Name),
                "date_asc" => query.OrderBy(s => s.CreatedDate),
                "date_desc" => query.OrderByDescending(s => s.CreatedDate),

                _ => query.OrderByDescending(s => s.Id),
            };


            vm.TotalCount = await query.CountAsync();

            var clients = await query
                          .Skip((vm.PageIndex - 1) *vm.PageSize).Take(vm.PageSize).ProjectTo <StaffBVM>(_mapper.ConfigurationProvider).ToListAsync();


            vm.Staffs = new StaticPagedList <StaffBVM>(clients, vm.PageIndex, vm.PageSize, vm.TotalCount);

            var categories = await _context.Organizations.AsNoTracking()
                             .OrderByDescending(d => d.Importance).ToListAsync();

            ViewData["Categories"] = new SelectList(categories, "Id", "Title");

            ViewBag.PageSizes = new SelectList(Site.PageSizes());

            return(View(vm));
        }