public virtual void SetUsersAt(ApplicationUser __item, int __index)
 {
     if (__item == null)
     {
         users[__index].RemoveRoles(this);
     }
     else
     {
         users[__index] = __item;
         if (!__item.Roles.Contains(this))
         {
             __item.AddRoles(this);
         }
     }
 }
 public virtual void AddUsers(ApplicationUser __item)
 {
     if (__item == null)
     {
         return;
     }
     if (!users.Contains(__item))
     {
         InternalAddUsers(__item);
     }
     if (!__item.Roles.Contains(this))
     {
         __item.AddRoles(this);
     }
 }
 public virtual void AddAtIndexUsers(int index, ApplicationUser __item)
 {
     if (__item == null)
     {
         return;
     }
     if (!users.Contains(__item))
     {
         users.Insert(index, __item);
     }
     if (!__item.Roles.Contains(this))
     {
         __item.AddRoles(this);
     }
 }
/// <summary>
/// Copies the current object to a new instance
/// </summary>
/// <param name="deep">Copy members that refer to objects external to this class (not dependent)</param>
/// <param name="copiedObjects">Objects that should be reused</param>
/// <param name="asNew">Copy the current object as a new one, ready to be persisted, along all its members.</param>
/// <param name="reuseNestedObjects">If asNew is true, this flag if set, forces the reuse of all external objects.</param>
/// <param name="copy">Optional - An existing [ApplicationUser] instance to use as the destination.</param>
/// <returns>A copy of the object</returns>
        public virtual ApplicationUser Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, ApplicationUser copy = null)
        {
            if (copiedObjects == null)
            {
                copiedObjects = new Hashtable();
            }
            if (copy == null && copiedObjects.Contains(this))
            {
                return((ApplicationUser)copiedObjects[this]);
            }
            copy = copy ?? new ApplicationUser();
            if (!asNew)
            {
                copy.TransientId = this.TransientId;
                copy.UserName    = this.UserName;
            }
            copy.PasswordHash         = this.PasswordHash;
            copy.SecurityStamp        = this.SecurityStamp;
            copy.EmailConfirmed       = this.EmailConfirmed;
            copy.LockoutEnabled       = this.LockoutEnabled;
            copy.PhoneNumberConfirmed = this.PhoneNumberConfirmed;
            copy.TwoFactorEnabled     = this.TwoFactorEnabled;
            copy.AccessFailedCount    = this.AccessFailedCount;
            copy.Name           = this.Name;
            copy.Email          = this.Email;
            copy.PhoneNumber    = this.PhoneNumber;
            copy.LockoutEndDate = this.LockoutEndDate;
            if (!copiedObjects.Contains(this))
            {
                copiedObjects.Add(this, copy);
            }
            copy.permissions = new List <ApplicationPermission>();
            if (deep && this.permissions != null)
            {
                foreach (var __item in this.permissions)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddPermissions(__item);
                        }
                        else
                        {
                            copy.AddPermissions(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddPermissions((ApplicationPermission)copiedObjects[__item]);
                    }
                }
            }
            copy.roles = new List <ApplicationRole>();
            if (deep && this.roles != null)
            {
                foreach (var __item in this.roles)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddRoles(__item);
                        }
                        else
                        {
                            copy.AddRoles(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddRoles((ApplicationRole)copiedObjects[__item]);
                    }
                }
            }
            copy.clients = new List <ApplicationClient>();
            if (deep && this.clients != null)
            {
                foreach (var __item in this.clients)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddClients(__item);
                        }
                        else
                        {
                            copy.AddClients(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddClients((ApplicationClient)copiedObjects[__item]);
                    }
                }
            }
            copy.logins = new List <ApplicationUserLogin>();
            if (deep && this.logins != null)
            {
                foreach (var __item in this.logins)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddLogins(__item);
                        }
                        else
                        {
                            copy.AddLogins(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddLogins((ApplicationUserLogin)copiedObjects[__item]);
                    }
                }
            }
            copy.claims = new List <ApplicationUserClaim>();
            if (deep && this.claims != null)
            {
                foreach (var __item in this.claims)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddClaims(__item);
                        }
                        else
                        {
                            copy.AddClaims(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddClaims((ApplicationUserClaim)copiedObjects[__item]);
                    }
                }
            }
            if (deep && this.profile != null)
            {
                if (!copiedObjects.Contains(this.profile))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.Profile = this.Profile;
                    }
                    else if (asNew)
                    {
                        copy.Profile = this.Profile.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.profile = this.profile.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.Profile = (Profile)copiedObjects[this.Profile];
                    }
                    else
                    {
                        copy.profile = (Profile)copiedObjects[this.Profile];
                    }
                }
            }
            return(copy);
        }