private IQueryable <UserGroup> ApplyOrder(IQueryable <UserGroup> queryUserGroups,
                                                  GroupFieldEnum orderField, OrderEnum order)
        {
            switch (orderField)
            {
            case GroupFieldEnum.name:
                if (order == OrderEnum.Ascending)
                {
                    queryUserGroups = queryUserGroups.OrderBy(x => x.name);
                }
                else
                {
                    queryUserGroups = queryUserGroups.OrderByDescending(x => x.name);
                }
                break;

            case GroupFieldEnum.description:
                if (order == OrderEnum.Ascending)
                {
                    queryUserGroups = queryUserGroups.OrderBy(x => x.description);
                }
                else
                {
                    queryUserGroups = queryUserGroups.OrderByDescending(x => x.description);
                }
                break;

            default:
                queryUserGroups = queryUserGroups.OrderBy(x => x.name);
                break;
            }
            return(queryUserGroups);
        }
        private IQueryable <UserGroup> ApplyFilter(IQueryable <UserGroup> queryUserGroups,
                                                   GroupFieldEnum fieldFilter, string fieldValue)
        {
            switch (fieldFilter)
            {
            case GroupFieldEnum.name:
                queryUserGroups = queryUserGroups.Where(x => x.name.Contains(fieldValue));
                break;

            case GroupFieldEnum.description:
                queryUserGroups = queryUserGroups.Where(x => x.description.Contains(fieldValue));
                break;

            default:
                break;
            }
            return(queryUserGroups);
        }
        public async Task <(List <UserGroup>, int)> getUserGroups(int startat, int quantity, GroupFieldEnum fieldFilter, string fieldValue, GroupFieldEnum orderField, OrderEnum order)
        {
            var queryUserGroups = _context.UserGroups.Where(x => x.enabled == true);

            queryUserGroups = ApplyFilter(queryUserGroups, fieldFilter, fieldValue);
            queryUserGroups = ApplyOrder(queryUserGroups, orderField, order);
            var users = await queryUserGroups.Include(x => x.users)
                        .Skip(startat).Take(quantity).ToListAsync();

            var queryUserGroupCount = _context.UserGroups.Where(x => x.enabled == true);

            queryUserGroupCount = ApplyFilter(queryUserGroupCount, fieldFilter, fieldValue);
            queryUserGroupCount = ApplyOrder(queryUserGroupCount, orderField, order);
            var totalCount = await queryUserGroupCount.CountAsync();

            return(users, totalCount);
        }