Example #1
0
 /// <summary>
 /// Merge changes inside entity <paramref name="from" /> to the entity <paramref name="to" />. Any changes in <paramref name="from" /> that is not changed in <paramref name="to" /> is updated inside <paramref name="to" />.
 /// </summary>
 /// <param name="from">The "old" entity acting as merging source.</param>
 /// <param name="to">The "new" entity which inherits changes made in <paramref name="from" />.</param>
 /// <returns>
 /// </returns>
 public static void MergeChanges(Role from, Role to)
 {
     if (to.IsPersisted)
     {
         if (from.IsCanBeDeletedModified && !to.IsCanBeDeletedModified)
         {
             to.CanBeDeleted = from.CanBeDeleted;
             to.IsCanBeDeletedModified = true;
         }
         if (from.IsRolePriorityModified && !to.IsRolePriorityModified)
         {
             to.RolePriority = from.RolePriority;
             to.IsRolePriorityModified = true;
         }
         if (from.IsDescriptionModified && !to.IsDescriptionModified)
         {
             to.Description = from.Description;
             to.IsDescriptionModified = true;
         }
         if (from.IsDisplayNameModified && !to.IsDisplayNameModified)
         {
             to.DisplayName = from.DisplayName;
             to.IsDisplayNameModified = true;
         }
     }
     else
     {
         to.IsPersisted = from.IsPersisted;
         to.ID = from.ID;
         to.RoleName = from.RoleName;
         to.CanBeDeleted = from.CanBeDeleted;
         to.IsCanBeDeletedModified = from.IsCanBeDeletedModified;
         to.RolePriority = from.RolePriority;
         to.IsRolePriorityModified = from.IsRolePriorityModified;
         to.Description = from.Description;
         to.IsDescriptionModified = from.IsDescriptionModified;
         to.DisplayName = from.DisplayName;
         to.IsDisplayNameModified = from.IsDisplayNameModified;
         to.ApplicationID = from.ApplicationID;
         to.ParentID = from.ParentID;
     }
 }
Example #2
0
 /// <summary>
 /// Update changes to the current entity compared to an input <paramref name="newdata" /> and set the entity to a proper state for updating.
 /// </summary>
 /// <param name="newdata">The "new" entity acting as the source of the changes, if any.</param>
 /// <returns>
 /// </returns>
 public void UpdateChanges(Role newdata)
 {
     int cnt = 0;
     if (CanBeDeleted != newdata.CanBeDeleted)
     {
         CanBeDeleted = newdata.CanBeDeleted;
         IsCanBeDeletedModified = true;
         cnt++;
     }
     if (RolePriority != newdata.RolePriority)
     {
         RolePriority = newdata.RolePriority;
         IsRolePriorityModified = true;
         cnt++;
     }
     if (Description != newdata.Description)
     {
         Description = newdata.Description;
         IsDescriptionModified = true;
         cnt++;
     }
     if (DisplayName != newdata.DisplayName)
     {
         DisplayName = newdata.DisplayName;
         IsDisplayNameModified = true;
         cnt++;
     }
     IsEntityChanged = cnt > 0;
 }
Example #3
0
 /// <summary>
 /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) primary key(s).
 /// </summary>
 /// <param name="other">The entity to be compared to.</param>
 /// <returns>
 ///   The result of comparison.
 /// </returns>
 public bool IsEntityIdentical(Role other)
 {
     if (other == null)
         return false;
     if (ID != other.ID)
         return false;
     return true;
 }              
Example #4
0
 /// <summary>
 /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) intrinsic identifiers.
 /// </summary>
 /// <param name="other">The entity to be compared to.</param>
 /// <returns>
 ///   The result of comparison.
 /// </returns>
 public bool IsEntityTheSame(Role other)
 {
     if (other == null)
         return false;
     else
         return RoleName == other.RoleName &&  ApplicationID == other.ApplicationID &&  ParentID == other.ParentID;
 }              
Example #5
0
 /// <summary>
 /// Internal use
 /// </summary>
 public Role ShallowCopy(bool allData = false, bool preserveState = false, bool checkLoadState = false)
 {
     Role e = new Role();
     e.StartAutoUpdating = false;
     e.ID = ID;
     e.RoleName = RoleName;
     e.CanBeDeleted = CanBeDeleted;
     if (preserveState)
         e.IsCanBeDeletedModified = IsCanBeDeletedModified;
     else
         e.IsCanBeDeletedModified = false;
     e.RolePriority = RolePriority;
     if (preserveState)
         e.IsRolePriorityModified = IsRolePriorityModified;
     else
         e.IsRolePriorityModified = false;
     e.DisplayName = DisplayName;
     if (preserveState)
         e.IsDisplayNameModified = IsDisplayNameModified;
     else
         e.IsDisplayNameModified = false;
     e.ApplicationID = ApplicationID;
     e.ParentID = ParentID;
     if (allData)
     {
         if (!checkLoadState || IsDescriptionLoaded)
             e.Description = Description;
         if (preserveState)
             e.IsDescriptionModified = IsDescriptionModified;
         else
             e.IsDescriptionModified = false;
         e.IsDescriptionLoaded = IsDescriptionLoaded;
     }
     e.DistinctString = GetDistinctString(true);
     e.IsPersisted = IsPersisted;
     if (preserveState)
         e.IsEntityChanged = IsEntityChanged;
     else
         e.IsEntityChanged = false;
     e.StartAutoUpdating = true;
     return e;
 }
Example #6
0
 /// <summary>
 /// <see cref="Role.UpperRef" /> is not initialized when the entity is created. Clients could call this method to load it provided a proper delegate <see cref="Role.DelLoadUpperRef" /> was setup
 /// before calling it.
 /// </summary>
 public void LoadUpperRef()
 {
     if (ParentID == null || _UpperRef != null)
         return;
     if (DelLoadUpperRef != null)
         _UpperRef = DelLoadUpperRef();
 }
Example #7
0
 public void UpdateInstance(Role r)
 {
     IsPersisted = false;
     Role.MergeChanges(r, this);
     IsPersisted = r.IsPersisted;
 }
 /// <summary>
 /// <see cref="UsersRoleHistory.RoleRef" /> is not initialized when the entity is created. Clients could call this method to load it provided a proper delegate <see cref="UsersRoleHistory.DelLoadRoleRef" /> was setup
 /// before calling it.
 /// </summary>
 public void LoadRoleRef()
 {
     if (_RoleRef != null)
         return;
     if (DelLoadRoleRef != null)
         _RoleRef = DelLoadRoleRef();
 }
 public static async Task<dynamic> CreateNewRole(string adminId, string name, int priority, int? pid)
 {
     var maxp = await MemberAdminContext.GetMaxPriority(adminId);
     if (maxp.Major < priority)
         return new { ok = false, msg = string.Format(ResourceUtils.GetString("0452f93e5e52c7eae26c4fac7aa2d5d7", "Denined! Your role priority: {0} is less than the requested one."), maxp.Major), role = new { } };
     RoleServiceProxy rsvc = new RoleServiceProxy();
     if (pid != null)
     {
         var prole = await rsvc.LoadEntityByKeyAsync(Cntx, pid.Value);
         if (prole.RolePriority >= priority)
             return new { ok = false, msg = string.Format(ResourceUtils.GetString("b1ac4f163f802b8cb0c9216a2845c96b", "Denined! The role priority: {0} is less than or equals to the one for the parent role."), priority), role = new { } };
     }
     Role r = new Role
     {
         RoleName = name,
         RolePriority = priority,
         ApplicationID = ApplicationContext.App.ID,
         DisplayName = name,
         ParentID = pid
     };
     var result = await rsvc.AddOrUpdateEntitiesAsync(Cntx, new RoleSet(), new Role[] { r });
     if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Added) > 0)
     {
         var rabs = new EntityAbs<Role>(result.ChangedEntities[0].UpdatedItem);
         rabs.ParentExists = pid != null;
         return new { ok = true, msg = "", role = MakeJsonRole(rabs, maxp) };
     }
     else
     {
         if ((result.ChangedEntities[0].OpStatus & (int)EntityOpStatus.Duplication) > 0)
             return new { ok = false, msg = ResourceUtils.GetString("a1794e1f262706c9409389bcfcff7499", "An existing role with the same name exists!"), role = new { } };
         else
             return new { ok = false, msg = ResourceUtils.GetString("aa1d969415687af8bf4e3ba5e4e3bc14", "Add failed, try again?"), role = new { } };
     }
 }
Example #10
0
 /// <summary>
 /// Internal use
 /// </summary>
 public Role ShallowCopy(bool allData = false)
 {
     Role e = new Role();
     e.IsInitializing = true;
     e.ID = ID;
     e.RoleName = RoleName;
     e.CanBeDeleted = CanBeDeleted;
     e.RolePriority = RolePriority;
     e.DisplayName = DisplayName;
     e.ApplicationID = ApplicationID;
     e.ParentID = ParentID;
     if (allData)
     {
         e.Description = Description;
     }
     e.DistinctString = GetDistinctString(true);
     e.IsPersisted = true;
     e.IsEntityChanged = false;
     e.IsInitializing = false;
     return e;
 }
Example #11
0
        /// <summary>
        /// Internal use
        /// </summary>
        public Role ShallowCopy(bool allData = false, bool preserveState = false)
        {
            Role e = new Role();

            e.StartAutoUpdating = false;
            e.ID           = ID;
            e.RoleName     = RoleName;
            e.CanBeDeleted = CanBeDeleted;
            if (preserveState)
            {
                e.IsCanBeDeletedModified = IsCanBeDeletedModified;
            }
            else
            {
                e.IsCanBeDeletedModified = false;
            }
            e.RolePriority = RolePriority;
            if (preserveState)
            {
                e.IsRolePriorityModified = IsRolePriorityModified;
            }
            else
            {
                e.IsRolePriorityModified = false;
            }
            e.DisplayName = DisplayName;
            if (preserveState)
            {
                e.IsDisplayNameModified = IsDisplayNameModified;
            }
            else
            {
                e.IsDisplayNameModified = false;
            }
            e.ApplicationID = ApplicationID;
            e.ParentID      = ParentID;
            if (allData)
            {
                e.Description = Description;
                if (preserveState)
                {
                    e.IsDescriptionModified = IsDescriptionModified;
                }
                else
                {
                    e.IsDescriptionModified = false;
                }
            }
            e.DistinctString = GetDistinctString(true);
            e.IsPersisted    = IsPersisted;
            if (preserveState)
            {
                e.IsEntityChanged = IsEntityChanged;
            }
            else
            {
                e.IsEntityChanged = false;
            }
            e.StartAutoUpdating = true;
            return(e);
        }