Beispiel #1
0
        /// <summary>
        /// Gets a user account.
        /// </summary>
        /// <param name="email">The email address.</param>
        /// <returns>The first user found with the specified email address, or <c>null</c>.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="email"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="email"/> is empty.</exception>
        public UserInfo GetUserByEmail(string email)
        {
            if (email == null)
            {
                throw new ArgumentNullException("email");
            }
            if (email.Length == 0)
            {
                throw new ArgumentException("Email cannot be empty", "email");
            }

            try {
                var userQuery = (from e in _context.CreateQuery <UserEntity>(UsersTable).AsTableServiceQuery()
                                 where e.PartitionKey.Equals(_wiki) && e.Email.Equals(email)
                                 select e).AsTableServiceQuery();
                UserEntity userEntity = QueryHelper <UserEntity> .FirstOrDefault(userQuery);

                // if the user does not exists return null
                if (userEntity == null)
                {
                    return(null);
                }

                return(new UserInfo(userEntity.RowKey, userEntity.DisplayName, userEntity.Email, userEntity.Active, new DateTime(userEntity.CreationDateTime.Ticks, DateTimeKind.Utc), this)
                {
                    Groups = userEntity.Groups != null?userEntity.Groups.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries) : new string[0]
                });
            }
            catch (Exception ex) {
                throw ex;
            }
        }
        private GlobalSettingsEntity GetGlobalSettingsEntity(string settingName)
        {
            var query = (from e in _context.CreateQuery <GlobalSettingsEntity>(GlobalSettingsTable).AsTableServiceQuery()
                         where e.PartitionKey.Equals("0") && e.RowKey.Equals(settingName)
                         select e).AsTableServiceQuery();

            return(QueryHelper <GlobalSettingsEntity> .FirstOrDefault(query));
        }
        private PluginEntity GetPluginEntity(string wiki, string typeName)
        {
            var query = (from e in _context.CreateQuery <PluginEntity>(PluginsTable).AsTableServiceQuery()
                         where e.PartitionKey.Equals(wiki) && e.RowKey.Equals(typeName)
                         select e).AsTableServiceQuery();

            return(QueryHelper <PluginEntity> .FirstOrDefault(query));
        }
Beispiel #4
0
        private UserDataEntity GetUserDataEntity(string _wiki, string username, string key)
        {
            var userDataQuery = (from e in _context.CreateQuery <UserDataEntity>(UserDataTable).AsTableServiceQuery()
                                 where e.PartitionKey.Equals(_wiki + "|" + username) && e.RowKey.Equals(key)
                                 select e).AsTableServiceQuery();

            return(QueryHelper <UserDataEntity> .FirstOrDefault(userDataQuery));
        }
Beispiel #5
0
        private UserGroupEntity GetUserGroupEntity(string wiki, string groupName)
        {
            if (_userGroups == null)
            {
                _userGroups = new Dictionary <string, UserGroupEntity>();
            }

            if (!_userGroups.ContainsKey(groupName))
            {
                var userGroupQuery = (from e in _context.CreateQuery <UserGroupEntity>(UserGroupsTable).AsTableServiceQuery()
                                      where e.PartitionKey.Equals(wiki) && e.RowKey.Equals(groupName)
                                      select e).AsTableServiceQuery();
                var entity = QueryHelper <UserGroupEntity> .FirstOrDefault(userGroupQuery);

                if (entity == null)
                {
                    return(null);
                }
                _userGroups[groupName] = entity;
            }
            return(_userGroups[groupName]);
        }