/// <summary> /// Processes a an member by creating a node for him/her(if it does not exists) and assigning the node reference to his/her membership record /// for postlogin redirections to right dashboard /// </summary> /// <param name="parentNodeIdAndKey"></param> /// <param name="memberToProcess"></param> private void ProcessMember(NodeIdAndKey <string, string> parentNodeIdAndKey, IMember memberToProcess) { if (parentNodeIdAndKey != null) // Physiotherapists node must exists in Data content. It is the parent of all physios { // Don't do following if it doesn't var foundNode = FindNode(parentNodeIdAndKey.NodeId, memberToProcess.Username); GuidUdi memberDataFolderValue; if (foundNode == null) // if node for new physiotherapist is not already created, then create it and grab its uid { var node = CreateNode(memberToProcess, parentNodeIdAndKey.NodeKey); memberDataFolderValue = node.GetUdi(); } else // if node for new physiotherapist is already there, then create it and grab its uid anyways { // using contextFactory is the recommended way of getting conten with V8 // <see href="https://our.umbraco.com/forum/umbraco-8/96270-using-umbracohelper-in-a-custom-class-in-v8"></see> using (var cref = _contextFactory.EnsureUmbracoContext()) { var node = cref.UmbracoContext.Content.GetById(int.Parse(foundNode.Id)); memberDataFolderValue = new GuidUdi("document", node.Key); } } // now set the uid to member's MemberDataFolder property memberToProcess.SetValue(GetMemberPropsAlias(m => m.MemberDataFolder), memberDataFolderValue); } }
/// <summary> /// It is responsible to create newly activated physio's data folder and link it to his/her membership record /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnMemberSavingHandler(IMemberService sender, SaveEventArgs <IMember> args) { List <string> processedNodesIds = new List <string>(); // To avoid chances to process same node multiple times - noticed it sometimes and could be a possible behaviour of umbraco foreach (IMember member in args.SavedEntities) { if (processedNodesIds.ContainsExt(member.Id.ToString())) // if not processed already, only then process it { continue; } if (member.IsApproved && MandatoryFieldsArePopulated(member)) { // create tree structure NodeIdAndKey <string, string> containerNodeIdAndKey = GetPhysiotherapistsContainerIdAndKey(); // we will (and should) have only one "Physiotherapists" content node to contain all the nodes phyios nodes // hence no further filtering - only look for the one with "Physiotherapists" alias ProcessMember(containerNodeIdAndKey, member); } processedNodesIds.Add(member.Id.ToString()); // Mark the member as processed - Note: I found that issue in intial implementation. // I left this logic as a precautionary measure. } }