public void Built_In_Member_Type_Properties_Missing_Are_Automatically_Added_When_Creating() { var stubs = Constants.Conventions.Member.GetStandardPropertyTypeStubs(); var provider = TestObjects.GetScopeProvider(Logger); using (provider.CreateScope()) { var repository = CreateRepository(provider); IMemberType memberType = MockedContentTypes.CreateSimpleMemberType(); // created without the stub properties Assert.AreEqual(1, memberType.PropertyGroups.Count); Assert.AreEqual(3, memberType.PropertyTypes.Count()); // add one stub property, others are still missing memberType.AddPropertyType(stubs.First().Value, Constants.Conventions.Member.StandardPropertiesGroupName); // saving *new* member type adds the (missing) stub properties repository.Save(memberType); // saving has added (and saved) the (missing) stub properties Assert.AreEqual(2, memberType.PropertyGroups.Count); Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count()); // getting with stub properties memberType = repository.Get(memberType.Id); Assert.AreEqual(2, memberType.PropertyGroups.Count); Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count()); } }
public void Built_In_Member_Type_Properties_Missing_Are_Automatically_Added_When_Creating() { Dictionary <string, PropertyType> stubs = ConventionsHelper.GetStandardPropertyTypeStubs(ShortStringHelper); IScopeProvider provider = ScopeProvider; using (provider.CreateScope()) { MemberTypeRepository repository = CreateRepository(provider); IMemberType memberType = MemberTypeBuilder.CreateSimpleMemberType(); // created without the stub properties Assert.AreEqual(1, memberType.PropertyGroups.Count); Assert.AreEqual(3, memberType.PropertyTypes.Count()); // add one stub property, others are still missing memberType.AddPropertyType(stubs.First().Value, Constants.Conventions.Member.StandardPropertiesGroupAlias, Constants.Conventions.Member.StandardPropertiesGroupName); // saving *new* member type adds the (missing) stub properties repository.Save(memberType); // saving has added (and saved) the (missing) stub properties Assert.AreEqual(2, memberType.PropertyGroups.Count); Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count()); // getting with stub properties memberType = repository.Get(memberType.Id); Assert.AreEqual(2, memberType.PropertyGroups.Count); Assert.AreEqual(3 + stubs.Count, memberType.PropertyTypes.Count()); } }
/// <summary> /// Add the custom properties to the Default Member Type /// receiveNotifications /// hasVerifiedAccount /// resetGuid /// joinedDate /// </summary> /// <returns></returns> private void AddMemberProperties() { bool saveMemberContent = false; var _memberTypeService = Current.Services.MemberTypeService; var _dataTypeService = Current.Services.DataTypeService; string groupname = "Forum Settings"; string mType = "Member"; var ds = Current.Services.LocalizationService; var newaccountType = ds.GetDictionaryItemByKey("ForumAuthConstants.NewAccountMemberType"); if (newaccountType != null) { mType = newaccountType.GetDefaultValue(); } IMemberType memberContentType = _memberTypeService.Get(mType); var dataTypeDefinitions = _dataTypeService.GetAll().ToArray(); //.ToArray() because arrays are fast and easy. var truefalse = dataTypeDefinitions.FirstOrDefault(p => p.EditorAlias.ToLower() == "umbraco.truefalse"); //we want the TrueFalse data type. var textbox = dataTypeDefinitions.FirstOrDefault(p => p.EditorAlias.ToLower() == "umbraco.textbox"); //we want the TextBox data type. try { if (!memberContentType.PropertyGroups.Contains(groupname)) { memberContentType.AddPropertyGroup(groupname); //add a property group, not needed, but I wanted it saveMemberContent = true; } if (!memberContentType.PropertyTypeExists("receiveNotifications")) { memberContentType.AddPropertyType(new PropertyType(truefalse) { Name = "Receive Notifications", Alias = "receiveNotifications", Description = "Get an email when someone posts in a topic you are participating.", Mandatory = false }, groupname); saveMemberContent = true; } if (!memberContentType.PropertyTypeExists("hasVerifiedAccount")) { memberContentType.AddPropertyType(new PropertyType(truefalse) { Name = "Has verified Email", Alias = "hasVerifiedAccount", Description = "User has verified their account.", Mandatory = false }, groupname); saveMemberContent = true; } if (!memberContentType.PropertyTypeExists("resetGuid")) { memberContentType.AddPropertyType(new PropertyType(textbox) { Name = "Reset Guid", Alias = "resetGuid", Description = "Guid set when user requests a password reset.", Mandatory = false }, groupname); saveMemberContent = true; } if (!memberContentType.PropertyTypeExists("joinedDate")) { memberContentType.AddPropertyType(new PropertyType(textbox) { Name = "Joined date", Alias = "joinedDate", Description = "Date the user joined (validated email).", Mandatory = false }, groupname); saveMemberContent = true; } if (saveMemberContent) { _memberTypeService.Save(memberContentType); //save the content type } } catch (Exception e) { Current.Logger.Error(System.Reflection.MethodBase.GetCurrentMethod().GetType(), e, "Executing ForumInstallHandler:Add member types"); } }
private string AddMemberProperties() { bool saveMemberContent = false; StringBuilder contentStatus = new StringBuilder(); string groupname = "Forum Settings"; string mType = "Member"; contentStatus.Append("<ul>"); var newaccountType = _localizationService.GetDictionaryItemByKey("ForumAuthConstants.NewAccountMemberType"); if (newaccountType != null) { mType = newaccountType.GetDefaultValue(); } IMemberType memberContentType = _memberTypeService.Get(mType); var dataTypeDefinitions = _dataTypeService.GetAll().ToArray(); //.ToArray() because arrays are fast and easy. var truefalse = dataTypeDefinitions.FirstOrDefault(p => p.EditorAlias.ToLower() == "umbraco.truefalse"); //we want the TrueFalse data type. var textbox = dataTypeDefinitions.FirstOrDefault(p => p.EditorAlias.ToLower() == "umbraco.textbox"); //we want the TextBox data type. try { if (!memberContentType.PropertyGroups.Contains(groupname)) { memberContentType.AddPropertyGroup(groupname); //add a property group, not needed, but I wanted it saveMemberContent = true; } contentStatus.Append("<li>"); if (!memberContentType.PropertyTypeExists("receiveNotifications")) { contentStatus.Append("Adding property receiveNotifications"); saveMemberContent = memberContentType.AddPropertyType(new PropertyType(truefalse) { Name = "Receive Notifications", Alias = "receiveNotifications", Description = "Get an email when someone posts in a topic you are participating.", Mandatory = false }, groupname); if (saveMemberContent) { memberContentType.SetMemberCanEditProperty("receiveNotifications", true); memberContentType.SetMemberCanViewProperty("receiveNotifications", true); } contentStatus.Append("<strong>done</strong>"); } else { memberContentType.SetMemberCanEditProperty("receiveNotifications", true); memberContentType.SetMemberCanViewProperty("receiveNotifications", true); } contentStatus.Append("</li><li>"); if (!memberContentType.PropertyTypeExists("hasVerifiedAccount")) { contentStatus.Append("Adding property hasVerifiedAccount"); saveMemberContent = memberContentType.AddPropertyType(new PropertyType(truefalse) { Name = "Has verified Email", Alias = "hasVerifiedAccount", Description = "User has verified their account.", Mandatory = false }, groupname); contentStatus.Append("<strong>done</strong>"); } contentStatus.Append("</li><li>"); if (!memberContentType.PropertyTypeExists("resetGuid")) { contentStatus.Append("Adding property resetGuid"); saveMemberContent = memberContentType.AddPropertyType(new PropertyType(textbox) { Name = "Reset Guid", Alias = "resetGuid", Description = "Guid set when user requests a password reset.", Mandatory = false }, groupname); if (saveMemberContent) { memberContentType.SetIsSensitiveProperty("resetGuid", true); } contentStatus.Append("<strong>done</strong>"); } contentStatus.Append("</li><li>"); if (!memberContentType.PropertyTypeExists("joinedDate")) { contentStatus.Append("Adding property joinedDate"); saveMemberContent = memberContentType.AddPropertyType(new PropertyType(textbox) { Name = "Joined date", Alias = "joinedDate", Description = "Date the user joined (validated email).", Mandatory = false }, groupname); if (saveMemberContent) { memberContentType.SetMemberCanViewProperty("joinedDate", true); } contentStatus.Append("<strong>done</strong>"); } contentStatus.Append("</li>"); if (saveMemberContent) { _memberTypeService.Save(memberContentType); //save the content type } else { throw new ArgumentException("Unable to add custom Member properties"); } } catch (Exception e) { Current.Logger.Error(System.Reflection.MethodBase.GetCurrentMethod().GetType(), e, "Executing ForumInstallHandler:Add member types"); contentStatus.Append($"<li>Error adding properties: {e.Message}</li>"); } contentStatus.Append("</ul>"); return(contentStatus.ToString()); }
/// <summary> /// This method uses the MemberTypeService to configure the defined memberType with all your custom properties, so that you don't have to add them manually /// You can extend or delete this for your own project /// @Html.ActionLink("Configure member properties", "ConfigureMemberProperties", "MemberConfig", new { memberTypeAlias = "Member" }, null) /// </summary> /// <returns></returns> public ActionResult ConfigureMemberProperties(string memberTypeAlias) { // Get the MemberTypeService and the MemberType var mts = Services.MemberTypeService; IMemberType memberType = mts.Get(memberTypeAlias); // Add the required properties: memberType.AddPropertyType(GetPropertyType("Joined Date", "joinedDate", PropertyEditor.Label)); memberType.AddPropertyType(GetPropertyType("Host Name of Last Login", "hostNameOfLastLogin", PropertyEditor.Label)); memberType.AddPropertyType(GetPropertyType("IP of Last Login", "iPOfLastLogin", PropertyEditor.Label)); memberType.AddPropertyType(GetPropertyType("Number of Logins", "numberOfLogins", PropertyEditor.Label)); memberType.AddPropertyType(GetPropertyType("Number of Profile Views", "numberOfProfileViews", PropertyEditor.Label)); memberType.AddPropertyType(GetPropertyType("Last Logged In", "lastLoggedIn", PropertyEditor.Label)); memberType.AddPropertyType(GetPropertyType("Reset GUID", "resetGUID", PropertyEditor.Label)); memberType.AddPropertyType(GetPropertyType("Has Verified Email", "hasVerifiedEmail", PropertyEditor.Boolean)); memberType.AddPropertyType(GetPropertyType("Email Verify GUID", "emailVerifyGUID", PropertyEditor.Label)); memberType.AddPropertyType(GetPropertyType("Description", "description", PropertyEditor.Text)); memberType.AddPropertyType(GetPropertyType("Profile URL", "profileURL", PropertyEditor.Label)); // Add your custom properties: memberType.AddPropertyType(GetPropertyType("LinkedIn", "linkedIn", PropertyEditor.Text)); memberType.AddPropertyType(GetPropertyType("Skype", "skype", PropertyEditor.Text)); memberType.AddPropertyType(GetPropertyType("Twitter", "twitter", PropertyEditor.Text)); // Update the membertype mts.Save(memberType); // Refresh the page return(Redirect("/")); }