Copied to clipboard

Flag this post as spam?

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


  • Joe Codino 25 posts 125 karma points
    Mar 19, 2016 @ 18:44
    Joe Codino
    0

    Unique property Value

    I've added a simple text property to the Member object. It should be unique so two members cannot have the same value for that property.

    How can I accomplish this?

    Thanks in advance

  • Aristotelis Pitaridis 84 posts 402 karma points
    Mar 19, 2016 @ 19:46
    Aristotelis Pitaridis
    0

    I suppose you create the members programmatically. You can get a unique id for each member using the Guid.

    String UniqueID = System.Guid.NewGuid().ToString;
    

    Now you can use this ID in order to store it for a Member.

  • Joe Codino 25 posts 125 karma points
    Mar 20, 2016 @ 09:51
    Joe Codino
    0

    Thanks for your reply, but I need to check the uniqueness of the value when a member edits his/her properties in the EditProfile.cshtml page... Probably the best way is to create a custom UmbProfileController.

  • Aristotelis Pitaridis 84 posts 402 karma points
    Mar 20, 2016 @ 14:53
    Aristotelis Pitaridis
    0

    What you mean when you say that you need to check the uniqueness? The user should type this unique value in order to be able to edit his profile? Tell me exactly what you want to do in order to be able to help you.

  • Joe Codino 25 posts 125 karma points
    Mar 20, 2016 @ 15:19
    Joe Codino
    0

    I have added a "forum nickname" textfield to the Member object, so a member can choose any nickname (different from the username) to use in the forum. I'm able to sync the nickname in Umbraco with the nickname in the forum to provide an unique login between the two websites, but I must be sure that if an Umbraco's member changes his/her nickname, this one must be unique to the Umbraco database (and obviously in the forum database, but they're always in sync)

  • Aristotelis Pitaridis 84 posts 402 karma points
    Mar 20, 2016 @ 15:29
    Aristotelis Pitaridis
    0

    So the member will submit an id and you want to test if it is unique. Try the following code.

    var ms = ApplicationContext.Current.Services.MemberService;
    string Value = "Test";
    var MembersFound = ms.GetMembersByPropertyValue("UniqueID", Value);
    if (MembersFound.Count() == 0)
    {
        // The id is unique so use it
    }
    else
    {
        // The id is not unique so ask user to define a new Unique id
    }
    

    The Value variable contains the id defined by the user. You ask all users that has as UniqueID property the value defined by the user. If you find a member with this condition then someone uses this id otherwise it is available.

    I have not tested it but it should work. Inform me if you have a problem with this code.

Please Sign in or register to post replies

Write your reply to:

Draft