Example #1
0
        /// <summary>
        /// Generate an empty, fake metadata item
        /// Important so that all ADAM items have a metadata - and don't throw errors when accessed
        /// </summary>
        /// <returns></returns>
        internal static Entity CreateFakeMetadata()
        {
            var emptyMetadata = new Dictionary <string, object> {
                { "Title", "" }
            };
            var fakeMeta = new Entity(Eav.Constants.TransientAppId, 0, ContentTypeBuilder.Fake(""), emptyMetadata,
                                      "Title");

            return(fakeMeta);
        }
Example #2
0
        private IEnumerable <ToSic.Eav.Interfaces.IEntity> GetList()
        {
            EnsureConfigurationIsLoaded();

            var properties = Properties.Split(',').Select(p => p.Trim()).ToArray();
            var portalId   = PortalSettings.Current.PortalId;

            // read all user Profiles
            ArrayList users;

            if (UserIds == "disabled")
            {
                users = UserController.GetUsers(portalId);
            }
            // read user Profiles of specified UserIds
            else
            {
                var userIds = UserIds.Split(',').Select(n => Convert.ToInt32(n)).ToArray();
                users = new ArrayList();
                foreach (var user in userIds.Select(userId => UserController.GetUserById(portalId, userId)))
                {
                    users.Add(user);
                }
            }

            // convert Profiles to Entities
            var result = new List <ToSic.Eav.Interfaces.IEntity>();

            foreach (UserInfo user in users)
            {
                // add Profile-Properties
                var values = new Dictionary <string, object>();
                foreach (var property in properties)
                {
                    string value;
                    switch (property.ToLower())
                    {
                    case "displayname":
                        value = user.DisplayName;
                        break;

                    case "email":
                        value = user.Email;
                        break;

                    case "firstname":
                        value = user.FirstName;
                        break;

                    case "lastname":
                        value = user.LastName;
                        break;

                    case "username":
                        value = user.Username;
                        break;

                    default:
                        value = user.Profile.GetPropertyValue(property);
                        break;
                    }

                    values.Add(property, value);
                }

                // create Entity and add to result
                var entity = new Eav.Data.Entity(Eav.Constants.TransientAppId, user.UserID, ContentTypeBuilder.Fake(ContentType), values, TitleField);
                result.Add(entity);
            }

            return(result);
        }