1

i am searching for a solution where it is possible to get a registration form in umbraco with a MemberType choice. I already found questions for getting membertypes of members that are already registered or questions about creating membertypes programmaticly but not something like a registration form where you are able to choose your future MemberType.

Furthermore i found some information about cmsPropertyData and that there are the member details are stored. But isn't there an easier solution then a manual SQL Query or to create an own RegistrationModel?

All i already have is the standard registration form:

var registerModel = Members.CreateRegistrationModel();

using (Html.BeginUmbracoForm<UmbRegisterController>("HandleRegisterMember"))
{
    <fieldset>
        <legend>Registrierung</legend>

        @Html.ValidationSummary("registerModel", true)

        <div class="form-group">
            @Html.LabelFor(m => registerModel.Name)
            @Html.TextBoxFor(m => registerModel.Name, new { @class = "form-control" })
            @Html.ValidationMessageFor(m => registerModel.Name)
        </div>

        <div class="form-group">
            @Html.LabelFor(m => registerModel.Email)
            @Html.TextBoxFor(m => registerModel.Email, new { @class = "form-control" })
            @Html.ValidationMessageFor(m => registerModel.Email)
        </div>
        <div class="form-group">
            @Html.LabelFor(m => registerModel.Password)
            @Html.PasswordFor(m => registerModel.Password, new { @class = "form-control" })
            @Html.ValidationMessageFor(m => registerModel.Password)
        </div>
        <div class="form-group">
        </div>

        @if (registerModel.MemberProperties != null)
        {
            for (var i = 0; i < registerModel.MemberProperties.Count; i++)
            {
                @Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.MemberProperties[i].Name)
                    @*
                By default this will render a textbox but if you want to change the editor template for this property you can
                easily change it. For example, if you wanted to render a custom editor for this field called "MyEditor" you would
                create a file at ~/Views/Shared/EditorTemplates/MyEditor.cshtml", then you will change the next line of code to
                render your specific editor template like:
                @Html.EditorFor(m => profileModel.MemberProperties[i].Value, "MyEditor")
                    *@
                @Html.EditorFor(m => registerModel.MemberProperties[i].Value)
                @Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
                <br/>
            }
        }

        @Html.HiddenFor(m => registerModel.MemberTypeAlias)
        @Html.HiddenFor(m => registerModel.RedirectUrl)
        @Html.HiddenFor(m => registerModel.UsernameIsEmail)

        <button class="btn btn-default">Registrieren</button>
    </fieldset>
}

Maybe some changes in the MembershipHelper?

I prefer to use the umbraco integrated membership method, but if there isn't any way to do this i think there won't be an alternative.

EDIT:

I change the way to do it like the follow:

First of all i get all MemberType with

var service = ApplicationContext.Services.MemberTypeService;
var memberTypes = service.GetAll();

then i go through a foreach loop with the memberTypes and give the Value to an Action Method:

@foreach (var memberType in memberTypes)
{
    <li>
        @Html.ActionLink("Als " + memberType.Alias, "RedirectToCorrectRegistrationForm", "RegistrationSurface", new { memberTypeAlias = memberType.Alias }, new { @class = "page-scroll" })
    </li>
}

The SurfaceController saves the memberType in a TempData and the registration form is able to handle with a memberTypeAlias

public ActionResult RedirectToCorrectRegistrationForm(string memberTypeAlias)
        {
            TempData["MemberType"] = memberTypeAlias;

            return RedirectToUmbracoPage(1072);
        }

Register.cshtml:

var registerModel = Members.CreateRegistrationModel(TempData["MemberType"].ToString());
Hardstyl3R
  • 23
  • 8

1 Answers1

0

If you just want to get all the MemberTypes that are currently present in your site you can use MemberTypeService as below.

var service = ApplicationContext.Services.MemberTypeService;
var memberTypes = service.GetAll();

You can even pass array of ints to GetAll() to get specific Types by their ids. You can iterate all its properties by accessing the .PropertyTypes of a single Membertype.

Chaitanya Gadkari
  • 2,669
  • 4
  • 30
  • 54
  • This might solve the problem of getting the MemberType's displayed in the registration form. But how do I link a selected MemberType with the rest of the registerModel? – Hardstyl3R Jun 30 '15 at 14:08
  • Also you should be using `SurfaceController`, `ApplicationContext` is not accessible in normal MVC Controller – Chaitanya Gadkari Jun 30 '15 at 14:10
  • Okay I tested your code and as you described the MemberTypes are shown, but nothing more. How is it possible to link the MemberType choice which is chosen for example with a dropdown box with the umbraco registrationModel? I am not pretty sure what the SurfaceController has to do with this? – Hardstyl3R Jun 30 '15 at 22:48
  • In SurfaceController you get service as `ApplicationContext.Services.MemberTypeService` and in normal Controller you have to get instance of current Context first. `ApplicationContext.Current.Services.MemberTypeService` nothing much, just SurfaceController provides more access to Umbraco features – Chaitanya Gadkari Jul 01 '15 at 05:13
  • so what more do you want from it, pass the chose type alias from dropdown and in code use that alias to create member of that type as `s.CreateMember("username","email","name","selectedAlias")` where s is `MemberService` – Chaitanya Gadkari Jul 01 '15 at 05:18
  • Well that sounds viable. I will test it later and give a feedback. – Hardstyl3R Jul 01 '15 at 13:04