public PersonalDataStructure GeneratePersonalData(UserGenderEnum? gender = null)
        {
            string contactDataUrl = "http://api.randomuser.me/0.4/";

            if (gender != null)
            {
                contactDataUrl = URLHelper.AddParameterToUrl(contactDataUrl, "gender", gender.Value == UserGenderEnum.Female ? "female" : "male");
            }

            string jsonResponse = new WebClient().DownloadString(contactDataUrl);

            dynamic response = JObject.Parse(jsonResponse);
            dynamic user = response.results[0].user;

            var capitalizer = new FirstLetterCapitalizer();

            var personalData = new PersonalDataStructure()
            {
                Gender = user.gender == "male" ? UserGenderEnum.Male : UserGenderEnum.Female,
                FirstName = capitalizer.CapitalizeFirstLetters((string)user.name.first),
                LastName = capitalizer.CapitalizeFirstLetters((string)user.name.last),
                Address = capitalizer.CapitalizeFirstLetters((string)user.location.street),
                City = capitalizer.CapitalizeFirstLetters((string)user.location.city),
                MobilePhone = user.cell,
                HomePhone = user.phone,
                ZIP = user.location.zip,
            };

            personalData.Email = personalData.FirstName + "." + personalData.LastName + "@" + StaticRandomCompanies.NextCompanyName() + ".com";

            return personalData;
        }
        public PersonalDataStructure GeneratePersonalData(UserGenderEnum? gender = null)
        {
            int contactNumber = StaticRandom.Next();

            string name;
            string lastName = "Doe" + contactNumber;
            gender = gender ?? (UserGenderEnum)(contactNumber % 3);
            if (gender.Value == UserGenderEnum.Male)
            {
                name = "John";
            }
            else if (gender.Value == UserGenderEnum.Female)
            {
                name = "Jolene";
            }
            else
            {
                name = "Dog";
                gender = UserGenderEnum.Unknown;
            }

            var personalData = new PersonalDataStructure()
            {
                Gender = gender.Value,
                FirstName = name,
                LastName = lastName,
                Address = name + " street",
                City = name + " city",
                MobilePhone = contactNumber.ToString(),
                HomePhone = (contactNumber * 2).ToString(),
                ZIP = (contactNumber * 3).ToString(),
            };

            personalData.Email = personalData.FirstName + "." + personalData.LastName + "@" + StaticRandomCompanies.NextCompanyName() + ".com";

            return personalData;
        }
    /// <summary>
    /// Sets image  url, width and height.
    /// </summary>
    protected void SetImage()
    {
        Visible = false;

        // Only if display picture is allowed
        if (DisplayPicture)
        {
            string imageUrl = ResolveUrl("~/CMSModules/Avatars/CMSPages/GetAvatar.aspx?avatarguid=");

            bool isGravatar = false;

            // Is user id set? => Get user info
            if (mUserId > 0)
            {
                // Get user info
                UserInfo ui = UserInfoProvider.GetUserInfo(mUserId);
                if (ui != null)
                {
                    switch (UserAvatarType)
                    {
                    case AvatarInfoProvider.AVATAR:
                        AvatarID = ui.UserAvatarID;
                        if (AvatarID <= 0)     // Backward compatibility
                        {
                            if (ui.UserPicture != "")
                            {
                                // Get picture filename
                                string filename = ui.UserPicture.Remove(ui.UserPicture.IndexOfCSafe('/'));
                                string ext      = Path.GetExtension(filename);
                                imageUrl += filename.Substring(0, (filename.Length - ext.Length));
                                imageUrl += "&extension=" + ext;
                                Visible   = true;
                            }
                            else if (UseDefaultAvatar)
                            {
                                UserGenderEnum gender = (UserGenderEnum)ValidationHelper.GetInteger(ui.UserSettings.UserGender, 0);
                                AvatarInfo     ai     = AvatarInfoProvider.GetDefaultAvatar(gender);

                                if (ai != null)
                                {
                                    AvatarID = ai.AvatarID;
                                }
                            }
                        }
                        break;

                    case AvatarInfoProvider.GRAVATAR:
                        int sideSize = mWidth > 0 ? mWidth : SettingsKeyInfoProvider.GetIntValue(SiteContext.CurrentSiteName + ".CMSAvatarMaxSideSize");
                        imageUrl   = AvatarInfoProvider.CreateGravatarLink(ui.Email, ui.UserSettings.UserGender, sideSize, SiteContext.CurrentSiteName);
                        isGravatar = true;
                        Visible    = true;
                        AvatarID   = 0;
                        break;
                    }
                }
            }
            else
            {
                // If user is public try get his gravatar
                if (UserAvatarType == AvatarInfoProvider.GRAVATAR)
                {
                    int sideSize = mWidth > 0 ? mWidth : SettingsKeyInfoProvider.GetIntValue(SiteContext.CurrentSiteName + ".CMSAvatarMaxSideSize");
                    imageUrl   = AvatarInfoProvider.CreateGravatarLink(UserEmail, (int)UserGenderEnum.Unknown, sideSize, SiteContext.CurrentSiteName);
                    isGravatar = true;
                    Visible    = true;
                    AvatarID   = 0;
                }
            }

            // Is group id set? => Get group info
            if (mGroupId > 0)
            {
                // Get group info trough module commands
                GeneralizedInfo gi = ModuleCommands.CommunityGetGroupInfo(mGroupId);
                if (gi != null)
                {
                    AvatarID = ValidationHelper.GetInteger(gi.GetValue("GroupAvatarID"), 0);
                }

                if ((AvatarID <= 0) && UseDefaultAvatar)
                {
                    AvatarInfo ai = AvatarInfoProvider.GetDefaultAvatar(DefaultAvatarTypeEnum.Group);
                    if (ai != null)
                    {
                        AvatarID = ai.AvatarID;
                    }
                }
            }

            if (AvatarID > 0)
            {
                AvatarInfo ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(AvatarID);
                if (ai != null)
                {
                    imageUrl += ai.AvatarGUID.ToString();
                    Visible   = true;
                }
            }


            // If item was found
            if (Visible)
            {
                if (!isGravatar)
                {
                    if (KeepAspectRatio)
                    {
                        imageUrl += "&maxsidesize=" + (Width > Height ? Width : Height);
                    }
                    else
                    {
                        imageUrl += "&width=" + Width + "&height=" + Height;
                    }
                }

                imageUrl      = HTMLHelper.EncodeForHtmlAttribute(imageUrl);
                ltlImage.Text = "<img alt=\"" + GetString("general.avatar") + "\" src=\"" + imageUrl + "\" />";

                // Render outer div with specific CSS class
                if (RenderOuterDiv)
                {
                    ltlImage.Text = "<div class=\"" + OuterDivCSSClass + "\">" + ltlImage.Text + "</div>";
                }
            }
        }
    }
        public PersonalDataStructure GeneratePersonalData(UserGenderEnum? gender = null)
        {
            string contactDataUrl = "http://api.randomuser.me/0.4/";

            if (gender != null)
            {
                contactDataUrl = URLHelper.AddParameterToUrl(contactDataUrl, "gender", gender.Value == UserGenderEnum.Female ? "female" : "male");
            }

            var serializer = new JavaScriptSerializer();
            string jsonResponse = new WebClient().DownloadString(contactDataUrl);

            dynamic response = serializer.DeserializeObject(jsonResponse);
            dynamic user = response["results"][0]["user"];

            var capitalizer = new FirstLetterCapitalizer();

            var personalData = new PersonalDataStructure
            {
                Gender = user["gender"] == "male" ? UserGenderEnum.Male : UserGenderEnum.Female,
                FirstName = capitalizer.CapitalizeFirstLetters((string)user["name"]["first"]),
                LastName = capitalizer.CapitalizeFirstLetters((string)user["name"]["last"]),
                Address = capitalizer.CapitalizeFirstLetters((string)user["location"]["street"]),
                City = capitalizer.CapitalizeFirstLetters((string)user["location"]["city"]),
                MobilePhone = user["cell"],
                HomePhone = user["phone"],
                ZIP = user["location"]["zip"],
            };

            personalData.Email = personalData.FirstName + "." + personalData.LastName + "@" + StaticRandomCompanies.NextCompanyName() + ".com";

            return personalData;
        }
Exemple #5
0
    /// <summary>
    /// Sets image  url, width and height.
    /// </summary>
    protected void SetImage()
    {
        Visible = false;

        // Only if display picture is allowed
        if (DisplayPicture)
        {
            string imageUrl = ResolveUrl("~/CMSModules/Avatars/CMSPages/GetAvatar.aspx?avatarguid=");

            // Is user id set? => Get user info
            if (mUserId > 0)
            {
                // Get user info
                UserInfo ui = UserInfoProvider.GetUserInfo(mUserId);
                if (ui != null)
                {
                    AvatarID = ui.UserAvatarID;
                    if (AvatarID <= 0)   // Backward compatibility
                    {
                        if (ui.UserPicture != "")
                        {
                            // Get picture filename
                            string filename = ui.UserPicture.Remove(ui.UserPicture.IndexOf('/'));
                            string ext      = Path.GetExtension(filename);
                            imageUrl += filename.Substring(0, (filename.Length - ext.Length));
                            imageUrl += "&extension=" + ext;
                            Visible   = true;
                        }
                        else if (UseDefaultAvatar)
                        {
                            DefaultAvatarTypeEnum defAvatar = DefaultAvatarTypeEnum.User;

                            // Get default avatar type according to user gender
                            UserGenderEnum gender = (UserGenderEnum)ValidationHelper.GetInteger(ui.GetValue("UserGender"), 0);
                            switch (gender)
                            {
                            case UserGenderEnum.Female:
                                defAvatar = DefaultAvatarTypeEnum.Female;
                                break;

                            case UserGenderEnum.Male:
                                defAvatar = DefaultAvatarTypeEnum.Male;
                                break;
                            }

                            AvatarInfo ai = AvatarInfoProvider.GetDefaultAvatar(defAvatar);

                            // Avatar not specified for current gender, get user default avatar
                            if (ai == null)
                            {
                                ai = AvatarInfoProvider.GetDefaultAvatar(DefaultAvatarTypeEnum.User);
                            }

                            if (ai != null)
                            {
                                AvatarID = ai.AvatarID;
                            }
                        }
                    }
                }
            }

            // Is group id set? => Get group info
            if (mGroupId > 0)
            {
                // Get group info trough module commands
                GeneralizedInfo gi = ModuleCommands.CommunityGetGroupInfo(mGroupId);
                if (gi != null)
                {
                    AvatarID = ValidationHelper.GetInteger(gi.GetValue("GroupAvatarID"), 0);
                }

                if ((AvatarID <= 0) && UseDefaultAvatar)
                {
                    AvatarInfo ai = AvatarInfoProvider.GetDefaultAvatar(DefaultAvatarTypeEnum.Group);
                    if (ai != null)
                    {
                        AvatarID = ai.AvatarID;
                    }
                }
            }

            if (AvatarID > 0)
            {
                AvatarInfo ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(AvatarID);
                if (ai != null)
                {
                    imageUrl += ai.AvatarGUID.ToString();
                    Visible   = true;
                }
            }

            // If item was found
            if (Visible)
            {
                if (KeepAspectRatio)
                {
                    imageUrl += "&maxsidesize=" + (Width > Height ? Width : Height);
                }
                else
                {
                    imageUrl += "&width=" + Width + "&height=" + Height;
                }
                imageUrl      = URLHelper.EncodeQueryString(imageUrl);
                ltlImage.Text = "<img alt=\"" + GetString("general.avatar") + "\" src=\"" + imageUrl + "\" />";

                // Render outer div with specific CSS class
                if (RenderOuterDiv)
                {
                    ltlImage.Text = "<div class=\"" + OuterDivCSSClass + "\">" + ltlImage.Text + "</div>";
                }
            }
        }
    }