0

I'm trying to create new member programaticaly. In fact I need to build a function to import members from a spreadsheet.

I build a Member class which inherits ProfileBase and can create one member programaticaly when he registers but that requires he logs in to update full profile. So a member registers, his membership is created, I log him in, create his profile and log him out. This is not visible for the user but works well in the background.

Now I need to to import members through a feature in the umbraco back office. I am able to create members but I am unable to update their profiles which use custom properties set up in web.config, umbraco and my Member class. I just get empty profile in my database.

Any idea what I can do in this case? How I can update a member profile without logging the member in? Thank you

apaderno
  • 28,547
  • 16
  • 75
  • 90
nickornotto
  • 1,946
  • 4
  • 36
  • 68
  • 1
    Just a quick comment so you are not reinventing the wheel, CMSImport can import members from Excel and the free edition can import up to 500 for your for free: http://soetemansoftware.nl/cmsimport/features – jakobandersen May 30 '13 at 12:42
  • Thanks @miracledev but I have more than 500 members and my company would not pay for a soft for just one off operation. Anyway I have built already all API I'm just not able to update the profiles if that makes sense – nickornotto May 30 '13 at 13:24
  • Can you post what code you have already? – Douglas Ludlow Jun 01 '13 at 15:02

1 Answers1

0

I did something very similar myself recently, assuming your Member class looks something like the following (or at least does the same thing).

public class MemberProfile : ProfileBase
{
    #region Firstname
    private const string FIRSTNAME = "_firstname";
    [SettingsAllowAnonymous(false)]
    public string FirstName
    {
        get
        {
            return GetCustomProperty(FIRSTNAME);
        }
        set
        {
            SetCustomProperty(FIRSTNAME, value);
        }
    } 
    #endregion

    #region Get and Set base properties

    private string GetCustomProperty(string propertyName)
    {
        var retVal = "";
        var prop = base.GetPropertyValue(propertyName);
        if (prop != null)
        {
            retVal = prop.ToString();
        }
        return retVal;
    }
    private void SetCustomProperty(string propertyName, object value)
    {
        var prop = base[propertyName];
        if (prop != null)
        {
            base.SetPropertyValue(propertyName, value);
        }
    }

    #endregion
}

Then using the following method should allow you to retrieve a member, update a property and save them:

var existingMember = MemberProfile.Create(username) as MemberProfile;
existingMember.FirstName = firstName;

existingMember.Save();

The confusing bit is that the Create() method actually returns existing users, they just called it create for some reason...

g7876413
  • 279
  • 2
  • 9