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)));
    }
Beispiel #2
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            UserIds  users = new UserIds();
            RolesIds roles = new RolesIds();

            modelBuilder.Entity <OrderProduct>()
            .HasKey(op => new { op.OrderId, op.ProductId });

            modelBuilder.Entity <User>()
            .HasMany(u => u.Orders)
            .WithOne(u => u.User)
            .HasForeignKey(u => u.UserId);

            modelBuilder.Entity <Order>()
            .HasMany(o => o.OrderProducts)
            .WithOne(o => o.Order)
            .HasForeignKey(o => o.OrderId);

            modelBuilder.Entity <Product>()
            .HasMany(p => p.OrderProducts)
            .WithOne(p => p.Product)
            .HasForeignKey(p => p.ProductId);

            modelBuilder.Entity <Invoice>()
            .HasOne(i => i.Order)
            .WithMany();

            modelBuilder.SeedUsers(roles, users);
            modelBuilder.SeedProducts();
            modelBuilder.SeedOrders(users);
            modelBuilder.SeedOrderProducts();
        }
        /// <summary>
        /// Дополнительные изменения в БД после обновления данных сущности в БД.
        /// </summary>
        /// <param name="db">контекст БД</param>
        /// <param name="entity">обновляемая в БД сущность</param>
        public void AfterUpdate(ApplicationDBContext db, Room entity)
        {
            if (UserIds == null)
            {
                return;
            }

            if (entity.Users == null)
            {
                entity.Users = new List <User>();
            }

            var userIdsToBeAdded = UserIds;
            var usersToBeDeleted = entity.Users
                                   .Where(us => UserIds.All(usId => usId != us.Id)).ToList();

            foreach (var user in usersToBeDeleted)
            {
                entity.Users.Remove(user);
            }

            userIdsToBeAdded = UserIds
                               .Where(usId => entity.Users.All(us => us.Id != usId)).ToList();

            foreach (var userId in userIdsToBeAdded)
            {
                entity.Users.Add(db.Set <User>().Find(userId));
            }
        }
Beispiel #4
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Uuid != null)
         {
             hashCode = hashCode * 59 + Uuid.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Description != null)
         {
             hashCode = hashCode * 59 + Description.GetHashCode();
         }
         if (TeamIds != null)
         {
             hashCode = hashCode * 59 + TeamIds.GetHashCode();
         }
         if (UserIds != null)
         {
             hashCode = hashCode * 59 + UserIds.GetHashCode();
         }
         if (DataPolicies != null)
         {
             hashCode = hashCode * 59 + DataPolicies.GetHashCode();
         }
         return(hashCode);
     }
 }
 private IReadOnlyList <NewsfeedPost> GetPostsForUser(IReadOnlyList <NewsfeedPost> posts, UserId userId)
 {
     return(posts.Select(v => new NewsfeedPost(
                             v.CreatorId,
                             v.PostId,
                             v.BlogId,
                             v.ChannelId,
                             v.PreviewText,
                             v.ImageId,
                             v.PreviewWordCount,
                             v.WordCount,
                             v.ImageCount,
                             v.FileCount,
                             v.VideoCount,
                             v.LiveDate,
                             v.ImageName,
                             v.ImageExtension,
                             v.ImageSize,
                             v.ImageRenderWidth,
                             v.ImageRenderHeight,
                             v.LikesCount,
                             v.CommentsCount,
                             UserIds.IndexOf(userId) < v.LikesCount,
                             v.CreationDate)).ToList());
 }
Beispiel #6
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);
        }
 internal List <string> AsString()
 {
     if (ProviderId == null)
     {
         return(UserIds);
     }
     return(UserIds.ConvertAll(x => ProviderId + ":" + x));
 }
Beispiel #8
0
 /// <summary>
 /// 编辑调用
 /// </summary>
 /// <param name="keyValue"></param>
 public override void Modify(string keyValue)
 {
     this.Id             = keyValue;
     this.ModifyDate     = DateTime.Now;
     this.ModifyUserId   = OperatorProvider.Provider.Current().UserId;
     this.ModifyUserName = OperatorProvider.Provider.Current().UserName;
     this.UserIds        = "," + UserIds.Trim(',') + ",";
 }
        public override string ToString()
        {
            StringBuilder __sb    = new StringBuilder("DDUpdateMembersRequest(");
            bool          __first = true;

            if (SessionId != null && __isset.sessionId)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("SessionId: ");
                __sb.Append(SessionId);
            }
            if (AppId != null && __isset.appId)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("AppId: ");
                __sb.Append(AppId);
            }
            if (GroupId != null && __isset.groupId)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("GroupId: ");
                __sb.Append(GroupId);
            }
            if (UserIds != null && __isset.userIds)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("UserIds: ");
                __sb.Append(UserIds.ToDebugString());
            }
            if (Info != null && __isset.info)
            {
                if (!__first)
                {
                    __sb.Append(", ");
                }
                __first = false;
                __sb.Append("Info: ");
                __sb.Append(Info == null ? "<null>" : Info.ToString());
            }
            __sb.Append(")");
            return(__sb.ToString());
        }
Beispiel #10
0
        /// <summary>
        /// Returns true if Team instances are equal
        /// </summary>
        /// <param name="other">Instance of Team to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Team other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Uuid == other.Uuid ||
                     Uuid != null &&
                     Uuid.Equals(other.Uuid)
                     ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Description == other.Description ||
                     Description != null &&
                     Description.Equals(other.Description)
                 ) &&
                 (
                     TeamIds == other.TeamIds ||
                     TeamIds != null &&
                     other.TeamIds != null &&
                     TeamIds.SequenceEqual(other.TeamIds)
                 ) &&
                 (
                     UserIds == other.UserIds ||
                     UserIds != null &&
                     other.UserIds != null &&
                     UserIds.SequenceEqual(other.UserIds)
                 ) &&
                 (
                     DataPolicyIds == other.DataPolicyIds ||
                     DataPolicyIds != null &&
                     other.DataPolicyIds != null &&
                     DataPolicyIds.SequenceEqual(other.DataPolicyIds)
                 ) &&
                 (
                     TermsOfServiceId == other.TermsOfServiceId ||
                     TermsOfServiceId != null &&
                     TermsOfServiceId.Equals(other.TermsOfServiceId)
                 ) &&
                 (
                     SubRealmId == other.SubRealmId ||
                     SubRealmId != null &&
                     SubRealmId.Equals(other.SubRealmId)
                 ));
        }
        private void FindCallerReceiverByIds(string receiverId, out UserIds caller, out UserIds receiver)
        {
            var connId = ChatHub.usersList
                         .Where(x => x.userId == User.Claims.First(c => c.Type == "UserID").Value)
                         .Select(x => x.connId)
                         .First();

            receiver = ChatHub.usersList.Find(r => r.userId == receiverId);
            caller   = ChatHub.usersList.Find(c => c.connId == connId);
        }
Beispiel #12
0
        public override void Process(XFireClient context)
        {
            var friends = context.Server.Database.QueryFriends(_ownerUser);

            friends.ForEach(f =>
            {
                UserIds.Add(f.UserId);
                Usernames.Add(f.Username);
                Nicks.Add(f.Nickname);
            });
        }
Beispiel #13
0
        public void Process(Context context)
        {
            var friends = context.Server.Database.QueryFriends(owner);

            friends.ForEach(f =>
            {
                UserIds.Add(f.UserId);
                Usernames.Add(f.Username);
                Nicks.Add(f.Nickname);
            });
        }
Beispiel #14
0
        public LocalMentionsBuilder WithUserIds(IEnumerable <Snowflake> userIds)
        {
            if (userIds == null)
            {
                throw new ArgumentNullException(nameof(userIds));
            }

            UserIds.Clear();
            UserIds.AddRange(userIds);
            return(this);
        }
Beispiel #15
0
 /// <summary>
 /// 新增调用
 /// </summary>
 public override void Create()
 {
     this.Id                 = string.IsNullOrEmpty(Id)?Guid.NewGuid().ToString():Id;
     this.CreateDate         = DateTime.Now;
     this.CreateUserId       = OperatorProvider.Provider.Current().UserId;
     this.CreateUserName     = OperatorProvider.Provider.Current().UserName;
     this.CreateUserDeptCode = OperatorProvider.Provider.Current().DeptCode;
     this.CreateUserOrgCode  = OperatorProvider.Provider.Current().OrganizeCode;
     this.CreateUserDeptName = string.IsNullOrEmpty(OperatorProvider.Provider.Current().DeptName) ? OperatorProvider.Provider.Current().OrganizeName : OperatorProvider.Provider.Current().DeptName;
     this.UserIds            = "," + UserIds.Trim(',') + ",";
 }
Beispiel #16
0
        public override async Task Process(IXFireClient client)
        {
            var friends = await client.Server.Database.QueryFriends(_ownerUser);

            foreach (var friend in friends)
            {
                var friendSession = client.Server.GetSession(friend);

                UserIds.Add(friend.Id);
                SessionIds.Add(friendSession?.SessionId ?? FriendIsOffLineSessionId);
            }
        }
        public override async Task Process(IXFireClient client)
        {
            var friends = (await client.Server.Database.QueryFriends(_ownerUser))
                          .Select(x => new { User = x, Session = client.Server.GetSession(x) })
                          .Where(x => x.Session != null);

            foreach (var friend in friends)
            {
                UserIds.Add(friend.User.Id);
                SessionIds.Add(friend.Session.SessionId);
            }
        }
        public override void Process(XFireClient client)
        {
            var friends = client.Server.Database.QueryFriends(_ownerUser);

            foreach (var friend in friends)
            {
                var friendSession = client.Server.GetSession(friend);

                UserIds.Add(friend.UserId);
                SessionIds.Add(friendSession != null ? friendSession.SessionId : FriendIsOffLineSessionId);
            }
        }
Beispiel #19
0
 public void DeleteUser()
 {
     try
     {
         User = AddUserM.GetUser(UserSelected);
         AddUserM.DeleteUser(User);
         UserIds.Remove(User.Id);
         (App.Current as App).navigation.MainWindows.comments.Text = "משתמש הוסר בהצלחה";
     }
     catch (Exception e)
     {
         (App.Current as App).navigation.MainWindows.comments.Text = e.Message.ToString();
     }
 }
Beispiel #20
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 #21
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 #22
0
        protected override void ProcessRecord()
        {
            var assignments = new UserAssignmentsDto
            {
                UserIds        = UserIds.Select(u => (long?)u).ToList(),
                RolesPerFolder = new List <FolderRolesDto>
                {
                    new FolderRolesDto
                    {
                        FolderId = Folder?.Id ?? Id.Value,
                        RoleIds  = RoleIds.Select(r => (int?)r).ToList()
                    }
                }
            };

            HandleHttpOperationException(() => Api_19_10.Folders.AssignUsers(new AssignUsersActionParameters(assignments)));
        }
Beispiel #23
0
        /// <summary>
        /// Returns true if Role instances are equal
        /// </summary>
        /// <param name="other">Instance of Role to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Role other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Uuid == other.Uuid ||
                     Uuid != null &&
                     Uuid.Equals(other.Uuid)
                     ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Description == other.Description ||
                     Description != null &&
                     Description.Equals(other.Description)
                 ) &&
                 (
                     FunctionIds == other.FunctionIds ||
                     FunctionIds != null &&
                     other.FunctionIds != null &&
                     FunctionIds.SequenceEqual(other.FunctionIds)
                 ) &&
                 (
                     UserIds == other.UserIds ||
                     UserIds != null &&
                     other.UserIds != null &&
                     UserIds.SequenceEqual(other.UserIds)
                 ) &&
                 (
                     RoleIds == other.RoleIds ||
                     RoleIds != null &&
                     other.RoleIds != null &&
                     RoleIds.SequenceEqual(other.RoleIds)
                 ));
        }
Beispiel #24
0
        public FollowedUser FollowUser([FromBody] UserIds userIds)
        {
            string userId                      = userIds.userId;
            string followedUserId              = userIds.followedUserId;
            GraphClientConnection graphClient  = new GraphClientConnection();
            FollowedUser          followedUser = new FollowedUser();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            string matchQuery        = "(user:User{id:'" + userId + "'})-[follow:FOLLOW]->(followedUser:User{id:'" + followedUserId + "'})";
            var    followedUserQuery = graphClient.client.Cypher
                                       .Match(matchQuery)
                                       .Return((followedUser) => new {
                FollowedUser = followedUser.As <FollowedUser>(),
            })
                                       .Results;

            if (followedUserQuery.Count() == 1) // relation between nodes exist already, so, you need to delete that relation
            {
                graphClient.client.Cypher
                .Match(matchQuery)
                .Delete("follow")
                .ExecuteWithoutResults();
                //204
                return(null);
            }

            var newFollowerQuery = graphClient.client.Cypher
                                   .Match("(user:User{id:'" + userId + "'}),(followedUser:User{id:'" + followedUserId + "'})")
                                   .Create("(user)-[:FOLLOW]->(followedUser)")
                                   .Return((followedUser) => new {
                FollowedUser = followedUser.As <FollowedUser>(),
            })
                                   .Results;

            followedUser.id     = newFollowerQuery.ToList()[0].FollowedUser.id;
            followedUser.name   = newFollowerQuery.ToList()[0].FollowedUser.name;
            followedUser.age    = newFollowerQuery.ToList()[0].FollowedUser.age;
            followedUser.gender = newFollowerQuery.ToList()[0].FollowedUser.gender;
            return(followedUser);
        }
Beispiel #25
0
        public void Process(Context context)
        {
            var friends = context.Server.Database.QueryFriends(owner);

            // offline friends are just not sent
            var friendsSessions = friends.Select(a => context.Server.GetSession(a))
                                  .Where(a => a != null)
                                  .ToList();

            friendsSessions.ForEach(session =>
            {
                UserIds.Add(session.User.UserId);
                SessionIds.Add(session.SessionId);
                Debug.WriteLine("Status: For:{0} -- FriendId:{1} Friend:{2} FriendSession:{3}", context.User.Username, session.User.UserId, session.User.Username, session.SessionId);
            });
            //friendsSessions.OrderBy(a => a.User.UserId);
            //friendsSessions.ForEach(session => Debug.WriteLine("Context: For:{0} -- FriendId:{1} Friend:{2} FriendSession:{3}", context.User.Username, session.User.UserId, session.User.Username, session.SessionId));
        }
Beispiel #26
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 new void AsCsvRow(CsvWriter writer, bool bulk = true)
        {
            base.AsCsvRow(writer, bulk);

            writer.WriteField(EnabledUser);
            writer.WriteField(String.Join(',', UserOrgs.Select(uo => uo.OrgId)));
            writer.WriteField(Role);
            writer.WriteField(Username);
            writer.WriteField(UserIds == null ? "" : String.Join(',', UserIds.Select(ui => $"{{{ui.Type}:{ui.Identifier}}}")));
            writer.WriteField(GivenName);
            writer.WriteField(FamilyName);
            writer.WriteField(MiddleName);
            writer.WriteField(Identifier);
            writer.WriteField(Email);
            writer.WriteField(SMS);
            writer.WriteField(Phone);
            writer.WriteField(String.Join(',', UserAgents.Select(ua => ua.AgentUserId)));
            writer.WriteField(String.Join(',', Grades));
            writer.WriteField(Password);

            writer.NextRecord();
        }
        /// <summary>
        /// Add parameters to the object model dictionary.
        /// </summary>
        /// <param name="dict">Dictionary to be updated with parameters.</param>
        protected override void AddParamsToDictionary(SortedDictionary <string, object> dict)
        {
            if (Pending.HasValue)
            {
                AddParam(dict, "pending", Pending.Value);
            }

            if (UserIds != null && UserIds.Any())
            {
                AddParam(dict, "ids", UserIds);
            }

            if (!string.IsNullOrEmpty(Prefix))
            {
                AddParam(dict, "prefix", Prefix);
            }

            if (!string.IsNullOrEmpty(SubAccountId))
            {
                AddParam(dict, "sub_account_id", SubAccountId);
            }
        }
        private int[] GetActorsArray(UserIds userIds)
        {
            switch (userIds)
            {
            case UserIds.NullId:
                return(null);

            case UserIds.UsrId3:
                return(new[] { 3 });

            case UserIds.UsrId2:
                return(new[] { 2 });

            case UserIds.UrId23:
                return(new[] { 2, 3 });

            case UserIds.WrogId:
                return(new[] { 6 });

            default:
                throw new ArgumentOutOfRangeException("userIds", userIds, null);
            }
        }
Beispiel #31
0
 public object Get(UserIds userIds)
 {
     return userIds.Ids.IsEmpty()
                ? Repository.GetAll()
                : Repository.GetByIds(userIds.Ids);
 }
Beispiel #32
0
 public void Delete(UserIds userIds)
 {
     Repository.DeleteByIds(userIds.Ids);
 }