Exemple #1
0
        //public async Task<int> GetNewestUserId(int siteId)
        //{
        //    return await dbSiteUser.GetNewestUserId(siteId);
        //}



        #endregion

        #region Roles

        /// <summary>
        /// Persists a new instance of Role. Returns true on success.
        /// when a role is created displayname corresponds to rolename
        /// but rolename can never change since it is used in a cookies and coded
        /// into security checks in some cases
        /// so subsequent changes to rolename really only effect displayname
        /// ie for localization or customization
        /// to really change a rolename you can delete the role and create a new one with the desired name
        /// some specific required system roles (Admin, Content Administrators)
        /// are also not allowed to be deleted
        /// </summary>
        /// <returns></returns>
        public async Task <bool> SaveRole(ISiteRole role)
        {
            if (role.RoleId == -1) // new role
            {
                bool exists = await RoleExists(role.SiteId, role.DisplayName);

                if (exists)
                {
                    log.LogError("attempt to create a duplicate role "
                                 + role.DisplayName + " for site "
                                 + role.SiteId.ToString());

                    return(false);
                }

                role.RoleGuid = Guid.NewGuid();

                role.RoleId = await dbRoles.RoleCreate(
                    role.RoleGuid,
                    role.SiteGuid,
                    role.SiteId,
                    role.DisplayName
                    );

                role.RoleName = role.DisplayName;

                return(role.RoleId > -1);
            }
            else
            {
                return(await dbRoles.Update(
                           role.RoleId,
                           role.DisplayName));
            }
        }
Exemple #2
0
        //public async Task<int> GetNewestUserId(int siteId)
        //{
        //    return await dbSiteUser.GetNewestUserId(siteId);
        //}



        #endregion

        #region Roles

        /// <summary>
        /// Persists a new instance of Role. Returns true on success.
        /// when a role is created displayname corresponds to rolename
        /// but rolename can never change since it is used in a cookies and coded
        /// into security checks in some cases
        /// so subsequent changes to rolename really only effect displayname
        /// ie for localization or customization
        /// to really change a rolename you can delete the role and create a new one with the desired name
        /// some specific required system roles (Admin, Content Administrators)
        /// are also not allowed to be deleted
        /// </summary>
        /// <returns></returns>
        public async Task <bool> SaveRole(ISiteRole role, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (role.RoleId == -1) // new role
            {
                bool exists = await RoleExists(role.SiteId, role.DisplayName, cancellationToken);

                if (exists)
                {
                    log.LogError("attempt to create a duplicate role "
                                 + role.DisplayName + " for site "
                                 + role.SiteId.ToString());

                    return(false);
                }

                role.RoleGuid = Guid.NewGuid();

                role.RoleId = await dbRoles.RoleCreate(
                    role.RoleGuid,
                    role.SiteGuid,
                    role.SiteId,
                    role.DisplayName
                    );

                role.RoleName = role.DisplayName;

                return(role.RoleId > -1);
            }
            else
            {
                return(await dbRoles.Update(
                           role.RoleId,
                           role.DisplayName));
            }
        }