Exemplo n.º 1
0
        public List <UserPaginationViewModel> GetUser_Pagination(int Skip)
        {
            var result = new List <UserPaginationViewModel>();
            var obj    = new UserPaginationViewModel();

            using (AstonContext dbContext = new AstonContext())
            {
                dbContext.Database.OpenConnection();
                DbCommand cmd = dbContext.Database.GetDbConnection().CreateCommand();
                cmd.CommandText = "dbo.sp_UserPagination";
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@Skip", SqlDbType.Int)
                {
                    Value = Skip
                });

                using (var reader = cmd.ExecuteReader())
                {
                    var Userlist = dbContext.DataReaderMapToList <UserPaginationViewModel>(reader);
                    foreach (var User in Userlist)
                    {
                        result.Add(User);
                    }
                    cmd.Connection.Close();
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public List <UserPaginationViewModel> GetUser_Pagination(int Skip)
        {
            var result = new List <UserPaginationViewModel>();
            var obj    = new UserPaginationViewModel();

            using (NpgsqlConnection connection =
                       new NpgsqlConnection(ConfigureSetting.GetConnectionString))
            {
                connection.Open();

                string sql = "sp_userpagination";


                using (NpgsqlCommand command =
                           new NpgsqlCommand(sql, connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@skip", NpgsqlTypes.NpgsqlDbType.Integer, Skip);

                    using (var reader = command.ExecuteReader())
                    {
                        result = DataReaderMap.DataReaderMapToList <UserPaginationViewModel>(reader);
                    }
                }
                connection.Close();
            }
            return(result);
        }
        public IActionResult Index(string searchString, int pageNum = 1, int pageSize = 3)
        {
            ViewBag.searchString = searchString;
            List <UserReadViewModel> users = _context.appUsers.Where(x => !string.IsNullOrEmpty(searchString) ? x.UserName.Contains(searchString) : true)
                                             .OrderBy(x => x.Id).Skip((pageNum - 1) * pageSize).Take(pageSize)
                                             .Select(n => new UserReadViewModel
            {
                Id       = n.Id,
                UserName = n.UserName,
                Gender   = n.Gender
            }).ToList();
            int TotalPage = (int)Math.Ceiling(Decimal.Divide(_context.appUsers.Count(x => !string.IsNullOrEmpty(searchString) ? x.UserName.Contains(searchString) : true), pageSize));

            UserPaginationViewModel PageData = new UserPaginationViewModel()
            {
                pagination = _paginationService.GetPagination(pageNum, pageSize, TotalPage),
                users      = users
            };

            return(View(PageData));
        }