Is it possible to create a member group programmatically
Hi.
I'm creating a memberservice, where I want to do the following:
Create a member
Create a page node for this member
Create a member group
Protect the page node with the group
I have created a controller and made this public ActionResult
[HttpPost]
public ActionResult HandleFormSubmit(FederationCreateAthleteFormViewModel model)
{
//
if (!ModelState.IsValid)
return CurrentUmbracoPage();
//Create member
var memberService = Services.MemberService;
if (memberService.GetByEmail(model.Email) != null)
{
ModelState.AddModelError("", "Atlet findes allerede med denne mail");
return CurrentUmbracoPage();
}
//FIND MEDIAFOLDER CONTAINER
var strMediaContainer = CurrentPage.GetPropertyValue("athleteMediaContainer").ToString();
int intMediaContainer = Int32.Parse(strMediaContainer);
IMedia MediaFolder = Services.MediaService.CreateMedia(model.Name, intMediaContainer, "Folder");
Services.MediaService.Save(MediaFolder);
var member = memberService.CreateMemberWithIdentity(model.Email, model.Email, model.Name, "dBwFAthlete");
member.SetValue("athleteMediaNode", MediaFolder.GetUdi().ToString());
memberService.SavePassword(member, model.Password);
Members.Login(model.Email, model.Password);
memberService.Save(member);
//FIND ATHLETE CONTAINER PAGE
var strAthleteContainer = CurrentPage.GetPropertyValue("athletePageContainer").ToString();
int intAthleteContainer = Int32.Parse(strAthleteContainer);
var newAthletePage = Services.ContentService.CreateContent(model.Name, intAthleteContainer, "federationAthletePage");
newAthletePage.SetValue("athleteMediaFolder", MediaFolder.GetUdi().ToString());
Services.ContentService.SaveAndPublishWithStatus(newAthletePage);
member.SetValue("dBwFAthletePage", newAthletePage.GetUdi().ToString());
//Create Member group with athlete name.
//var mg = Services.MemberGroupService;
//Protect Athletepage with created group
//add coaches to membergroup
memberService.Save(member);
return RedirectToCurrentUmbracoPage();
//return Redirect("/");
}
But I am stuck where I need to create the member group. Can anybody help me?
Is it possible to create a member group programmatically
Hi.
I'm creating a memberservice, where I want to do the following:
I have created a controller and made this public ActionResult
But I am stuck where I need to create the member group. Can anybody help me?
This code snippet should help you. I have provided snippet for Create Member group & Protect Athletepage with created group.
//Create Member group with athlete name. var mg = Services.MemberGroupService; var memberGroup = new MemberGroup { Name = {athlete name} };
mg.Save(memberGroup);
var Id = memberGroup.Id;
//Protect Athletepage with created group var publicAccessService = ApplicationContext.Current.Services.PublicAccessService;
// Get IContent that should be protectet. var content = contentService.GetById(1000);
// Get the current role for the content var entry = publicAccessService.GetEntryForContent(content);
// Update entry entry.LoginNodeId = 1500; entry.NoAccessNodeId = 1660; entry.AddRule("MemberRole", {athlete name}); publicAccessService.Save(entry);
is working on a reply...