Пример #1
0
 public void DeleteApplicationPermission(zAppDev.DotNet.Framework.Identity.Model.ApplicationPermission applicationpermission, bool doNotCallDeleteForThis = false, bool isCascaded = false, object calledBy = null)
 {
     if (applicationpermission == null || applicationpermission.IsTransient())
     {
         return;
     }
     if (applicationpermission.Roles.Count > 0)
     {
         var cs = new System.Data.ConstraintException("applicationpermission.Roles elements are restricted and cannot be deleted");
         cs.Data["Entity"]       = "ApplicationPermission";
         cs.Data["PropertyName"] = "Roles";
         cs.Data["Multiplicity"] = "*";
         throw cs;
     }
     if (applicationpermission.Users.Count > 0)
     {
         var cs = new System.Data.ConstraintException("applicationpermission.Users elements are restricted and cannot be deleted");
         cs.Data["Entity"]       = "ApplicationPermission";
         cs.Data["PropertyName"] = "Users";
         cs.Data["Multiplicity"] = "*";
         throw cs;
     }
     foreach (var toDissasociate in applicationpermission.Operations)
     {
         applicationpermission.RemoveOperations(toDissasociate);
     }
     if (!doNotCallDeleteForThis)
     {
         Delete <zAppDev.DotNet.Framework.Identity.Model.ApplicationPermission>(applicationpermission, isCascaded);
     }
 }
 public virtual void AddAtIndexPermissions(int index, ApplicationPermission __item)
 {
     if (__item == null)
     {
         return;
     }
     if (!permissions.Contains(__item))
     {
         permissions.Insert(index, __item);
     }
     if (!__item.Users.Contains(this))
     {
         __item.AddUsers(this);
     }
 }
 public virtual void AddPermissions(ApplicationPermission __item)
 {
     if (__item == null)
     {
         return;
     }
     if (!permissions.Contains(__item))
     {
         InternalAddPermissions(__item);
     }
     if (!__item.Users.Contains(this))
     {
         __item.AddUsers(this);
     }
 }
/// <summary>
///     Returns true if self and the provided entity have the same Id values
///     and the Ids are not of the default Id value
/// </summary>
        protected bool HasSameNonDefaultIdAs(ApplicationPermission compareTo)
        {
            return(!this.IsTransient() && !compareTo.IsTransient() && this.Id.Equals(compareTo.Id));
        }
/// <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 [ApplicationPermission] instance to use as the destination.</param>
/// <returns>A copy of the object</returns>
        public virtual ApplicationPermission Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, ApplicationPermission copy = null)
        {
            if (copiedObjects == null)
            {
                copiedObjects = new Hashtable();
            }
            if (copy == null && copiedObjects.Contains(this))
            {
                return((ApplicationPermission)copiedObjects[this]);
            }
            copy = copy ?? new ApplicationPermission();
            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.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.operations = new List <ApplicationOperation>();
            if (deep && this.operations != null)
            {
                foreach (var __item in this.operations)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddOperations(__item);
                        }
                        else
                        {
                            copy.AddOperations(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddOperations((ApplicationOperation)copiedObjects[__item]);
                    }
                }
            }
            return(copy);
        }