public virtual void AddAtIndexRoles(int index, ApplicationRole __item)
 {
     if (__item == null)
     {
         return;
     }
     if (!roles.Contains(__item))
     {
         roles.Insert(index, __item);
     }
     if (!__item.Permissions.Contains(this))
     {
         __item.AddPermissions(this);
     }
 }
 public virtual void SetRolesAt(ApplicationRole __item, int __index)
 {
     if (__item == null)
     {
         roles[__index].RemovePermissions(this);
     }
     else
     {
         roles[__index] = __item;
         if (!__item.Permissions.Contains(this))
         {
             __item.AddPermissions(this);
         }
     }
 }
 public virtual void AddRoles(ApplicationRole __item)
 {
     if (__item == null)
     {
         return;
     }
     if (!roles.Contains(__item))
     {
         InternalAddRoles(__item);
     }
     if (!__item.Permissions.Contains(this))
     {
         __item.AddPermissions(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 [ApplicationRole] instance to use as the destination.</param>
/// <returns>A copy of the object</returns>
        public virtual ApplicationRole Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, ApplicationRole copy = null)
        {
            if (copiedObjects == null)
            {
                copiedObjects = new Hashtable();
            }
            if (copy == null && copiedObjects.Contains(this))
            {
                return((ApplicationRole)copiedObjects[this]);
            }
            copy = copy ?? new ApplicationRole();
            if (!asNew)
            {
                copy.TransientId = this.TransientId;
                copy.Id          = this.Id;
            }
            copy.Name        = this.Name;
            copy.Description = this.Description;
            copy.IsCustom    = this.IsCustom;
            if (!copiedObjects.Contains(this))
            {
                copiedObjects.Add(this, copy);
            }
            copy.users = new List <ApplicationUser>();
            if (deep && this.users != null)
            {
                foreach (var __item in this.users)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddUsers(__item);
                        }
                        else
                        {
                            copy.AddUsers(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddUsers((ApplicationUser)copiedObjects[__item]);
                    }
                }
            }
            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]);
                    }
                }
            }
            return(copy);
        }