Beispiel #1
0
        public bool CanEnterGroup(Guid userId, bool isPlatformAdmin = false)
        {
            // Platform admins can always enter all groups
            if (isPlatformAdmin)
            {
                return(true);
            }

            // Open groups can be entered by everyone
            if (GroupType == GroupType.Open)
            {
                return(true);
            }

            // Hidden and private groups by admins and users of that group and platform admins
            if (GroupType == GroupType.Hidden || GroupType == GroupType.Private)
            {
                if (AdminIds != null && AdminIds.Contains(userId))
                {
                    return(true);
                }
                if (UserIds != null && UserIds.Contains(userId))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
 private bool TryChangeSet(ISet <string> set, string userId, bool isAdd)
 {
     if (UserIds.Contains(userId))
     {
         if (isAdd)
         {
             set.Add(userId);
         }
         else
         {
             set.Remove(userId);
         }
         return(true);
     }
     return(false);
 }
Beispiel #3
0
        public Expression <Func <UserEntity, bool> > GetExpression()
        {
            Expression <Func <UserEntity, bool> > expression = oo => 1 == 1;

            if (UserIds?.Count > 0)
            {
                expression = expression.And(oo => UserIds.Contains(oo.UserId));
            }

            if (!string.IsNullOrEmpty(SearchKey))
            {
                expression = expression.And(oo => oo.UserName.Contains(SearchKey));
            }

            return(expression);
        }
Beispiel #4
0
        public IQueryable <AuditLogItem> GetDbQuery(IQueryable <AuditLogItem> query)
        {
            query = query.Where(o => o.GuildId == GuildId);

            if (UserIds != null)
            {
                query = query.Where(o => UserIds.Contains(o.UserId.Value));
            }

            if (Types?.Length > 0)
            {
                query = query.Where(o => Types.Contains(o.Type));
            }

            if (From != null)
            {
                query = query.Where(o => o.CreatedAt >= From.Value);
            }

            if (To != null)
            {
                query = query.Where(o => o.CreatedAt < To.Value);
            }

            if (IgnoredIds?.Count > 0)
            {
                query = query.Where(o => !IgnoredIds.Contains(o.UserId.Value));
            }

            if (ChannelIds != null)
            {
                var channels = ChannelIds.Select(o => o.ToString()).ToArray();
                query = query.Where(o => channels.Contains(o.ChannelId));
            }

            if (SortDesc)
            {
                return(query.OrderByDescending(o => o.CreatedAt).ThenByDescending(o => o.Id));
            }
            else
            {
                return(query.OrderBy(o => o.CreatedAt).ThenBy(o => o.Id));
            }
        }
        public IQueryable <Client> Create(IQueryable <Client> query, IApplicationGuidFactory guidFactory)
        {
            query = query.Where(i => (i.AllowedGrantTypes & GrantTypes.ClientCredentials) == GrantTypes.ClientCredentials);

            if (UserId != null)
            {
                return(query.Where(i => guidFactory.CreateGuid(i) == UserId));
            }

            if (UserIds?.Count > 0)
            {
                return(query.Where(i => UserIds.Contains(guidFactory.CreateGuid(i))));
            }

            if (UserName != null)
            {
                query = query.Where(i => EF.Functions.Like(i.ClientId, $"%{UserName}%"));
            }

            return(query);
        }
    public bool Equals(Group objectToCompare)
    {
        if (objectToCompare == null)
        {
            return(false);
        }

        if (ReferenceEquals(this, objectToCompare))
        {
            return(true);
        }

        if (UserIds.Count != objectToCompare.UserIds.Count || CreateByUserId != objectToCompare.CreateByUserId)
        {
            return(false);
        }

        //If you need equality when order matters - use this
        //return UserIds.SequenceEqual(objectToCompare.UserIds);


        //This is for set equality. If this is your case and you don't allow duplicates then I would suggest to use HashSet<int> or ISet<int> instead of Collection<int>
        //and use their methods for more concise and effective comparison
        return(UserIds.All(id => objectToCompare.UserIds.Contains(id)) && objectToCompare.UserIds.All(id => UserIds.Contains(id)));
    }