public async Task <IActionResult> GetPagedUserDepartment([FromQuery] UserDepartmentParams userDepartmentParams)
        {
            var userDepartment = await userDepartmentRepository.GetPagedUserDepartment(userDepartmentParams);

            var result = mapper.Map <IEnumerable <ViewUserDepartmentResource> >(userDepartment);

            Response.AddPagination(userDepartment.CurrentPage, userDepartment.PageSize, userDepartment.TotalCount, userDepartment.TotalPages);

            return(Ok(result));
        }
        public async Task <PagedList <UserDepartment> > GetPagedUserDepartment(UserDepartmentParams userDepartmentParams)
        {
            var userDepartments = context.UserDepartment.AsQueryable();

            if (userDepartmentParams.UserId > 0)
            {
                userDepartments = userDepartments.Where(u => u.UserId == userDepartmentParams.UserId);
            }

            if (userDepartmentParams.DepartmentId > 0)
            {
                userDepartments = userDepartments.Where(u => u.DepartmentId == userDepartmentParams.DepartmentId);
            }

            // sort
            if (userDepartmentParams.isDescending)
            {
                if (!string.IsNullOrEmpty(userDepartmentParams.OrderBy))
                {
                    switch (userDepartmentParams.OrderBy.ToLower())
                    {
                    case "userid":
                        userDepartments = userDepartments.OrderByDescending(u => u.UserId);
                        break;

                    case "departmentid":
                        userDepartments = userDepartments.OrderByDescending(u => u.DepartmentId);
                        break;

                    default:
                        userDepartments = userDepartments.OrderByDescending(u => u.UserId);
                        break;
                    }
                }
                else
                {
                    userDepartments = userDepartments.OrderByDescending(u => u.UserId);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(userDepartmentParams.OrderBy))
                {
                    switch (userDepartmentParams.OrderBy.ToLower())
                    {
                    case "userid":
                        userDepartments = userDepartments.OrderBy(u => u.UserId);
                        break;

                    case "departmentid":
                        userDepartments = userDepartments.OrderBy(u => u.DepartmentId);
                        break;

                    default:
                        userDepartments = userDepartments.OrderBy(u => u.UserId);
                        break;
                    }
                }
                else
                {
                    userDepartments = userDepartments.OrderBy(u => u.UserId);
                }
            }

            return(await PagedList <UserDepartment> .CreateAsync(userDepartments, userDepartmentParams.PageNumber, userDepartmentParams.PageSize));
        }