Ejemplo n.º 1
0
        private void UpdateUsersRolesList(IStorageSession session, UserEntity userEntity, IEnumerable <string> newRoles)
        {
            var newRolesList = newRoles.Any()
                                   ? session.Query <RoleEntity>(staleResults: StaleResultsMode.WaitForNonStaleResults)
                               .ContainsIn(r => r.RoleName, newRoles)
                               .ToList()
                                   : Enumerable.Empty <RoleEntity>();

            var roleNamesToRemove = userEntity.GetRolesToRemove(newRoles);

            foreach (var roleName in roleNamesToRemove)
            {
                if (userEntity.RemoveRole(roleName))
                {
                    _log.Debug(m => m("remove role by name {0}", roleName));
                }
            }

            foreach (var roleEntity in newRolesList)
            {
                if (userEntity.AddRole(roleEntity.RoleName))
                {
                    _log.Debug(m => m("Added user {0} to role {1}", userEntity, roleEntity));
                }
            }
        }
Ejemplo n.º 2
0
        private Page <User> GetPageOfUsersMatchedToTerm(string column, string term, string applicationName, PageCriteria pageCriteria)
        {
            if (string.IsNullOrWhiteSpace(term))
            {
                var usersQuery = _session.Query <UserEntity>();
                if (!string.IsNullOrWhiteSpace(applicationName))
                {
                    usersQuery = usersQuery.Where(u => u.ApplicationName == applicationName);
                }
                return(Pagination
                       .From(usersQuery.OrderBy(u => u.Username))
                       .Page(pageCriteria.PageNumber, pageCriteria.PageSize)
                       .GetPageWithItemsMappedBy(u => u.ToUser()));
            }

            var session = ((RavenDbSession)_session).Session;
            var query   = session.Advanced.LuceneQuery <UserEntity>();

            if (string.IsNullOrWhiteSpace(applicationName))
            {
                query = session.Advanced.LuceneQuery <UserEntity>()
                        .Where(string.Format("{0}:*{1}*", column, term));
            }
            else
            {
                query = session.Advanced.LuceneQuery <UserEntity>()
                        .Where(string.Format("{0}:*{1}* AND ApplicationName:{2}", column, term, applicationName));
            }
            var allMatchedUsers = query
                                  .OrderBy(u => u.Username)
                                  .WaitForNonStaleResultsAsOfLastWrite()
                                  .ToList();

            return(Pagination
                   .From(allMatchedUsers.AsQueryable())
                   .Page(pageCriteria.PageNumber, pageCriteria.PageSize)
                   .GetPageWithItemsMappedBy(u => u.ToUser()));
        }
Ejemplo n.º 3
0
 public IQueryable <T> Query <T>(ILoadingStrategy <T> loadingStrategy = null, StaleResultsMode staleResults = StaleResultsMode.AllowStaleResultsMode)
 {
     return(_outsideSession.Query(loadingStrategy, staleResults));
 }
Ejemplo n.º 4
0
        private void UpdateUsersRolesList(IStorageSession session, UserEntity userEntity, IEnumerable<string> newRoles)
        {
            var newRolesList = newRoles.Any()
                                   ? session.Query<RoleEntity>(staleResults: StaleResultsMode.WaitForNonStaleResults)
                                         .ContainsIn(r => r.RoleName, newRoles)
                                         .ToList()
                                   : Enumerable.Empty<RoleEntity>();

            var roleNamesToRemove = userEntity.GetRolesToRemove(newRoles);
            foreach (var roleName in roleNamesToRemove)
            {
                if (userEntity.RemoveRole(roleName))
                {
                    _log.Debug(m => m("remove role by name {0}", roleName));
                }
            }

            foreach (var roleEntity in newRolesList)
            {
                if (userEntity.AddRole(roleEntity.RoleName))
                {
                    _log.Debug(m => m("Added user {0} to role {1}", userEntity, roleEntity));
                }
            }
        }