Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Barry Fogarty 493 posts 1129 karma points
    Sep 15, 2011 @ 18:26
    Barry Fogarty
    0

    Type conflict in Memertype

    Firstly just let me say I really enjoy working with uSiteBuilder and love your work in general.

     

    I have a strange problem at the minute, when trying to output a list of all my members using MemberHelper.GetAllMembers()

     

    Cannot set the value of a Member type property SiteMember.EmailIsPublic (member type: System.Int32) to value: '' (value type: ). Error: Input string was not in a correct format.

     

    So 'EmailIsPublic' is a true/false in the database, and in my SiteMember.cs I have declared the property as public int EmailIsPublic (bool does not work either).  I am assuming the reason is that some members do not have this flag (i.e. email is not public).  WHat is the best way to handle this scenario?  Do I have to declare them all as strings and convert, or is there a better way?

  • Vladan Ostojic 94 posts 210 karma points
    Sep 15, 2011 @ 23:08
    Vladan Ostojic
    0

    Thanks Barry.

    Are all your members of SiteMember member type, or you have multiple member types? Can you paste the code of SiteMember.cs. Which version of uSiteBuilder are you using?

  • Barry Fogarty 493 posts 1129 karma points
    Sep 15, 2011 @ 23:17
    Barry Fogarty
    0

    Hi Vladan.  I am using 1.1.  All my members are of the same (SiteMember) type.  Here is my code (FYI I have changes the offending ints to strings temporarily so I can continue to work at the moment, but obviously I would rather have the right types:  (all the properties with ...IsPublic should be ideally bools, or ints)

    I guess one solution would be to ensure all values are initialised with something when the account is first created, but this would not be great for the backoffice (e.g. having a -1 in some numeric fields, rather than them being blank)

    [MemberType]
        public class SiteMember : MemberTypeBase
        {
            public SiteMember(string login, string email, string password) : base(login, email, password)
            {}

            [MemberTypeProperty(UmbracoPropertyType.Other, OtherTypeName = "Member Title", Tab = "Personal Details")]
            public string Title { get; set; }
           
            [MemberTypeProperty(UmbracoPropertyType.Textstring, Tab="Personal Details")]
            public string FirstName { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Textstring, Tab = "Personal Details")]
            public string LastName { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Other, OtherTypeName = "Region dropdown", Tab = "Personal Details")]
            public string Region { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Textstring, Tab = "Contact Details")]
            public string Address1 { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Textstring, Tab = "Contact Details")]
            public string Address2 { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Textstring, Tab = "Contact Details")]
            public string Postcode { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Textstring, Tab = "Contact Details")]
            public string City { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Textstring, Tab = "Contact Details")]
            public string Country { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Textstring, Tab = "Contact Details")]
            public string Phone { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.TrueFalse, Tab = "History", Name = "Still Working?")]
            public string IsWorking { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.TrueFalse, Tab = "History", Name = "Retired?")]
            public string IsRetired { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Numeric, Tab = "History", Name = "Year of Retirement", Description = "e.g. 2014")]
            public string YearOfRetirement { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Textstring, Tab = "History", Name = "Current / Most recent Job Title", Description = "")]
            public string JobTitle1 { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Textstring, Tab = "History", Name = "Previous Job Title at ", Description = "Used in the member search")]
            public string JobTitle2 { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Textstring, Tab = "History", Name = "Previous Job Title at ", Description = "Also used in the member search")]
            public string JobTitle3 { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.TrueFalse, Tab = "Preferences", Name = "Show profile in directory?", Description = "A switch to allow the member to keep their profile private")]
            public string ProfileIsPublic { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.TrueFalse, Tab = "Preferences", Name = "Allow site messages?", Description = "Uncheck to hide message button in member directory")]
            public string EmailIsPublic { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.TrueFalse, Tab = "Preferences", Name = "Show location on profile?", Description = "Uncheck to hide location in member directory")]
            public string RegionIsPublic { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.TrueFalse, Tab = "Preferences", Name = "Show years at on profile?", Description = "Uncheck to hide number of years worked in member directory")]
            public string YearsIsPublic { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.TrueFalse, Tab = "Preferences", Name = "Show job title on profile?", Description = "Uncheck to hide job title in member directory")]
            public string JobTitleIsPublic { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Other, OtherTypeName = "Communication Types", Tab = "Preferences", Name = "Contact Preferences", Description = "Communication methods preferred by the member")]
            public string CommsPrefs { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Other, OtherTypeName = "Interests", Tab = "Preferences", Name = "Interested in", Description = "Information categories the member is interested in receiving")]
            public string InterestedIn { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.TextboxMultiple, Tab = "Biography", Name = "Biography / Work history", Description = "A summary of the member's life and career")]
            public string Bio { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.TextboxMultiple, Tab = "Biography", Name = "Hobbies and interests", Description = "")]
            public string Hobbies { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.Other, OtherTypeName = "Friend List", Tab = "Friends")]
            public string Friends { get; set; }

            [MemberTypeProperty(UmbracoPropertyType.MediaPicker, Tab = "Photo")]
            public string Photo { get; set; }

            public static SiteMember GetMemberFromUrl()
            {
                //Get the member Id from the URL
                int memberId;
                int.TryParse(HttpContext.Current.Request.QueryString["id"], out memberId);
                return MemberHelper.GetMemberById(memberId) as SiteMember;
            }

            public static string GetMemberNameFromUrl()
            {
                //Get the member name from the URL  (there is a custom rewrite rule in place)
                string memberName = HttpContext.Current.Request.QueryString["name"];
                if (!String.IsNullOrEmpty(memberName))
                {
                    memberName = memberName.Replace('-', ' ');
                }
                return memberName;
            }

  • Vladan Ostojic 94 posts 210 karma points
    Sep 15, 2011 @ 23:26
    Vladan Ostojic
    0

    It is possible that for some of your members for some properties values are empty so uSiteBuilder don't know which value to set (true or false). Try change the property as following:

     

    public bool? EmailIsPublic { get; set; }

    (so bool is now nullable)

  • Barry Fogarty 493 posts 1129 karma points
    Sep 16, 2011 @ 00:23
    Barry Fogarty
    0

    Thanks Vladan.  I think you are right in the source of the error.  I made the changes to use a nullable bool but I recieved the following error:

    Cannot set the value of a Member type property SiteMember.IsWorking (member type: System.Nullable`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]) to value: '' (value type: ). Error: String was not recognized as a valid Boolean.

    This is on attempting to create a brand new member so I have no idea why it is returning an empty string fomr the DB as it seems to be saying.  THe IsWorking property has always  been a True/False, not sure how to trace this through as there would not be any data stored for this member.

  • Barry Fogarty 493 posts 1129 karma points
    Sep 16, 2011 @ 00:42
    Barry Fogarty
    0

    A bit of clarification - I am creating a new member in the Umbraco backoffice first, just setting the core umbraco proprties.   I get the above error after they log in and when an instance of the SiteMember class is created:

    SiteMember currentMember = MemberHelper.GetCurrentMember() as SiteMember;

  • Vladan Ostojic 94 posts 210 karma points
    Sep 16, 2011 @ 09:22
    Vladan Ostojic
    0

    Can you tell me which error do you get when you declare a property as:

    public bool EmailIsPublic { get; set; }

    (so it's not nullable). 

  • Barry Fogarty 493 posts 1129 karma points
    Sep 17, 2011 @ 01:16
    Barry Fogarty
    0

    Hi Vladan, I cleared out all my test user accounts and it seems to be behaving now with bools.  For ints, if I create a new member in the backoffice, and then try to create my SiteMember object via memberhelper, it errors out with the above 'input string not in a correct format' type error.  This happens for me whether I use a standard or nullable int.

    However my situation is that I will be preloading member data so rather than leaving these values as nulls (or empty strings as they seem to be coming out of the DB) I will give them a default value of the correct type.  Its good to have bools working so far as I cannot give these a default value.

     

     

  • Barry Fogarty 493 posts 1129 karma points
    Sep 17, 2011 @ 18:16
    Barry Fogarty
    0

    Hi Vladan, thanks again for helping me look into this.  I am back looking at the INT issue as it transpires I do need these as ints natively.  To recap when I set a membertype property to an INT, create a test member from the backoffice, and then access the macro where I create a MemberHelper.GetCurrentMember() as SiteMember instance, I get the following:

    Error loading Razor Script ~/macroscripts/signup.cshtml
    Cannot set the value of a Member type property SiteMember.YearsAtX (member type: System.Int32) to value: '' (value type: ). Error: Input string was not in a correct format.

    If I try using a nullable property, I get the following:

    Error loading Razor Script ~/macroscripts/signup.cshtml
    Cannot set the value of a Member type property SiteMember.YearsAtX (member type: System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]) to value: '' (value type: ). Error: Input string was not in a correct format.

     

    I havent poked around in the uSiteBuilder code |(yet), but can you confirm what happens in uSiteBuilder when a NULL property value is found from the database.  I would have thought it would return a NULL to the class property, but it is returning an empty string (or so it would seem) which means I cannot instance my prorties of the correct types.  If this is the case maybe I can modify the source code and contribute it back in, with a bit of guidance :-)

  • Vladan Ostojic 94 posts 210 karma points
    Sep 20, 2011 @ 09:10
    Vladan Ostojic
    0

    Thanks for letting me know about this. This is a bug in uSiteBuilder and we'll fix it asap.

  • Barry Fogarty 493 posts 1129 karma points
    Sep 30, 2011 @ 17:26
    Barry Fogarty
    0

    Hi Vladan, just wondering if there is any patch for this.  I have a site going live that uses uSiteBuilder membertypes, and I am facing an issue that if a new member is created from the backoffice, it does not set nullable ints (which is fine) - but as described above when I access my MemberHelper.GetCurrentMember() for this member, I get the input not in the correct format error.  Its kinda stopping the site go live so any advice/patch/workaround you can offer would be fantastic.

  • Vladan Ostojic 94 posts 210 karma points
    Sep 30, 2011 @ 18:27
    Vladan Ostojic
    0

    Hi Barry,

    Ok, I made a small change to uSiteBuilder code related to this feature but didn't test it thoroughly. You can take the latest version from SVN and try it. I also have a dll ready so if you give me your email I can send you the dll directly.

     

     

     

  • Barry Fogarty 493 posts 1129 karma points
    Sep 30, 2011 @ 18:41
    Barry Fogarty
    0

    Great stuff Vladan, superfast response!   its barryfogarty

    and then the rest is

    AT :  gmail

    and the ususal dot and com at the end.

  • Barry Fogarty 493 posts 1129 karma points
    Oct 01, 2011 @ 14:11
    Barry Fogarty
    0

    Thanks again for your heml.  Unfortunately I am still getting the error.  I have worked around by initialising the offending properties to 0 using a Member.NewEventHandler in ApplicationBase.

    If you want I can test out an update in your next release for this issue.  CHeers for looking at it so quickly, still love uSiteBuilder and hopefully it will go from strength top strength.  On a little asside, it would be nice to have a flag NOT to set icon urls - I like to use a package for this and a rebuild will overwrite settings made in the Umbraco UI.  Maybe this could be a general thing e.g. doctype names, property descriptions etc?

Please Sign in or register to post replies

Write your reply to:

Draft