public IActionResult LoadData()
        {
            List <DataTableUserView> data = new List <DataTableUserView>();

            try
            {
                var draw = HttpContext.Request.Form["draw"].FirstOrDefault();

                // Skip number of Rows count
                var start = Request.Form["start"].FirstOrDefault();

                // Paging Length 10,20
                var length = Request.Form["length"].FirstOrDefault();

                // Sort Column Name
                var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault();

                sortColumn = string.IsNullOrWhiteSpace(sortColumn) ? "RegistrationNumber" : sortColumn;
                // Sort Column Direction (asc, desc)
                var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault();

                // Search Value from (Search box)
                var searchValue = Request.Form["search[value]"].FirstOrDefault();

                //Paging Size (10, 20, 50,100)
                int pageSize = length != null?Convert.ToInt32(length) : 0;

                int skip = start != null?Convert.ToInt32(start) : 0;

                UserPaginationModel paginationModel = new UserPaginationModel
                {
                    SortColumn          = sortColumn,          //"RegistrationNumber"
                    SortColumnDirection = sortColumnDirection, // "asc"
                    SearchValue         = searchValue,         //""
                    PageSize            = pageSize,            //10
                    Skip = skip                                //0
                };

                // getting all Customer data
                data = _userService.GetUsers(paginationModel, out int recordsTotal);
                return(Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data }));
            }
            catch (Exception)
            {
                UserPaginationModel paginationModel = new UserPaginationModel
                {
                    SortColumn          = "RegistrationNumber",
                    SortColumnDirection = "asc",
                    SearchValue         = "",
                    PageSize            = 10,
                    Skip = 0
                };
                data = _userService.GetUsers(paginationModel, out int recordsTotal);
                return(Json(new { draw = "1", recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data }));
            }
        }
Ejemplo n.º 2
0
        public JsonResult _GridTest(UserPaginationModel userModel)
        {
            if (userModel.ID == 0)
            {
                userModel.ID = 1;
            }
            var dto1 = userDbContext.getTenUser(userModel.ID);

            userModel = pageMapper.Map <UserPaginationDTO, UserPaginationModel>(dto1);
            return(Json(userModel, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UserPaginationList(int page = 1)
        {
            int pageSize = 3;   // количество элементов на странице

            IQueryable <User> source = db.Users.Include(x => x.Company);
            var count = await source.CountAsync();

            var items = await source.Skip((page - 1) *pageSize).Take(pageSize).ToListAsync();

            PageViewModel       pageViewModel = new PageViewModel(count, page, pageSize);
            UserPaginationModel viewModel     = new UserPaginationModel
            {
                PageViewModel = pageViewModel,
                Users         = items
            };

            return(View(viewModel));
        }
Ejemplo n.º 4
0
        public List <Users> GetUsersRepository(UserPaginationModel paginationModel, out int recordsTotal)
        {
            var userData = (from tempUsers in _gymManagementContext.Users
                            select tempUsers);

            userData = userData.OrderBy(paginationModel.SortColumn + " " + paginationModel.SortColumnDirection);

            //Search
            if (!string.IsNullOrEmpty(paginationModel.SearchValue))
            {
                userData = userData.Where(m => m.Name.StartsWith(paginationModel.SearchValue));
            }

            //Total Records
            recordsTotal = userData.Count();

            //Paging
            var data = userData.Skip(paginationModel.Skip).Take(paginationModel.PageSize).ToList();

            return(data);
        }
Ejemplo n.º 5
0
        public List <DataTableUserView> GetUsers(UserPaginationModel paginationModel, out int recordsTotal)
        {
            var allUsers = _userRepository.GetUsersRepository(paginationModel, out recordsTotal);

            return(ViewModelParser.GetDTUserViews(allUsers));
        }