From 9236225bdf09bdf995abde5684178812fd73f80e Mon Sep 17 00:00:00 2001 From: Morten Christensen Date: Fri, 15 Aug 2014 14:42:05 +0200 Subject: [PATCH] Adding and updating code comments for the Membership service interfaces and implementations --- .../Models/Membership/IMembershipUser.cs | 4 +- src/Umbraco.Core/Services/IMemberService.cs | 166 +++++---- .../Services/IMembershipMemberService.cs | 183 ++++++---- .../Services/IMembershipUserService.cs | 10 + src/Umbraco.Core/Services/MemberService.cs | 323 ++++++++++-------- 5 files changed, 433 insertions(+), 253 deletions(-) diff --git a/src/Umbraco.Core/Models/Membership/IMembershipUser.cs b/src/Umbraco.Core/Models/Membership/IMembershipUser.cs index b304f72777..1aead03726 100644 --- a/src/Umbraco.Core/Models/Membership/IMembershipUser.cs +++ b/src/Umbraco.Core/Models/Membership/IMembershipUser.cs @@ -1,9 +1,11 @@ using System; -using System.Collections.Generic; using Umbraco.Core.Models.EntityBase; namespace Umbraco.Core.Models.Membership { + /// + /// Defines the base contract for and + /// public interface IMembershipUser : IAggregateRoot { object ProviderUserKey { get; set; } diff --git a/src/Umbraco.Core/Services/IMemberService.cs b/src/Umbraco.Core/Services/IMemberService.cs index 5d78f6df86..82c21dd2fc 100644 --- a/src/Umbraco.Core/Services/IMemberService.cs +++ b/src/Umbraco.Core/Services/IMemberService.cs @@ -5,128 +5,180 @@ using Umbraco.Core.Persistence.Querying; namespace Umbraco.Core.Services { - /// /// Defines the MemberService, which is an easy access to operations involving (umbraco) members. /// public interface IMemberService : IMembershipMemberService { - int Count(string contentTypeAlias = null); - + /// + /// Creates an object without persisting it + /// + /// This method is convenient for when you need to add properties to a new Member + /// before persisting it in order to limit the amount of times its saved. + /// Also note that the returned will not have an Id until its saved. + /// Username of the Member to create + /// Email of the Member to create + /// Name of the Member to create + /// Alias of the MemberType the Member should be based on + /// IMember CreateMember(string username, string email, string name, string memberTypeAlias); + + /// + /// Creates an object without persisting it + /// + /// This method is convenient for when you need to add properties to a new Member + /// before persisting it in order to limit the amount of times its saved. + /// Also note that the returned will not have an Id until its saved. + /// Username of the Member to create + /// Email of the Member to create + /// Name of the Member to create + /// MemberType the Member should be based on + /// IMember CreateMember(string username, string email, string name, IMemberType memberType); + + /// + /// Creates and persists a Member + /// + /// Using this method will persist the Member object before its returned + /// meaning that it will have an Id available (unlike the CreateMember method) + /// Username of the Member to create + /// Email of the Member to create + /// Name of the Member to create + /// Alias of the MemberType the Member should be based on + /// IMember CreateMemberWithIdentity(string username, string email, string name, string memberTypeAlias); + + /// + /// Creates and persists a Member + /// + /// Using this method will persist the Member object before its returned + /// meaning that it will have an Id available (unlike the CreateMember method) + /// Username of the Member to create + /// Email of the Member to create + /// Name of the Member to create + /// MemberType the Member should be based on + /// IMember CreateMemberWithIdentity(string username, string email, string name, IMemberType memberType); /// /// This is simply a helper method which essentially just wraps the MembershipProvider's ChangePassword method /// - /// The member to save the password for - /// - /// - /// This method exists so that Umbraco developers can use one entry point to create/update members if they choose to. - /// + /// This method exists so that Umbraco developers can use one entry point to create/update + /// Members if they choose to. + /// The Member to save the password for + /// The password to encrypt and save void SavePassword(IMember member, string password); /// - /// Checks if a member with the id exists + /// Gets the count of Members by an optional MemberType alias /// - /// - /// + /// If no alias is supplied then the count for all Member will be returned + /// Optional alias for the MemberType when counting number of Members + /// with number of Members + int Count(string memberTypeAlias = null); + + /// + /// Checks if a Member with the id exists + /// + /// Id of the Member + /// True if the Member exists otherwise False bool Exists(int id); /// - /// Get a member by the unique key + /// Gets a Member by the unique key /// - /// - /// + /// The guid key corresponds to the unique id in the database + /// and the user id in the membership provider. + /// Id + /// IMember GetByKey(Guid id); /// - /// Gets a member by it's id + /// Gets a Member by its integer id /// - /// - /// + /// Id + /// IMember GetById(int id); /// - /// Get all members for the member type alias + /// Gets all Members for the specified MemberType alias /// - /// - /// + /// Alias of the MemberType + /// IEnumerable GetMembersByMemberType(string memberTypeAlias); /// - /// Get all members for the member type id + /// Gets all Members for the MemberType id /// - /// - /// + /// Id of the MemberType + /// IEnumerable GetMembersByMemberType(int memberTypeId); /// - /// Get all members in the member group name specified + /// Gets all Members within the specified MemberGroup name /// - /// - /// + /// Name of the MemberGroup + /// IEnumerable GetMembersByGroup(string memberGroupName); /// - /// Get all members with the ids specified + /// Gets all Members with the ids specified /// - /// - /// + /// If no Ids are specified all Members will be retrieved + /// Optional list of Member Ids + /// IEnumerable GetAllMembers(params int[] ids); /// - /// Delete members of the specified member type id + /// Delete Members of the specified MemberType id /// - /// + /// Id of the MemberType void DeleteMembersOfType(int memberTypeId); /// - /// Find members based on their display name + /// Finds Members based on their display name /// - /// - /// - /// - /// - /// - /// + /// Display name to match + /// Current page index + /// Size of the page + /// Total number of records found (out) + /// The type of match to make as . Default is + /// IEnumerable FindMembersByDisplayName(string displayNameToMatch, int pageIndex, int pageSize, out int totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith); /// - /// Get members based on a property search + /// Gets a list of Members based on a property search /// - /// - /// - /// - /// + /// Alias of the PropertyType to search for + /// Value to match + /// The type of match to make as . Default is + /// IEnumerable GetMembersByPropertyValue(string propertyTypeAlias, string value, StringPropertyMatchType matchType = StringPropertyMatchType.Exact); /// - /// Get members based on a property search + /// Gets a list of Members based on a property search /// - /// - /// - /// - /// + /// Alias of the PropertyType to search for + /// Value to match + /// The type of match to make as . Default is + /// IEnumerable GetMembersByPropertyValue(string propertyTypeAlias, int value, ValuePropertyMatchType matchType = ValuePropertyMatchType.Exact); /// - /// Get members based on a property search + /// Gets a list of Members based on a property search /// - /// - /// - /// + /// Alias of the PropertyType to search for + /// Value to match + /// IEnumerable GetMembersByPropertyValue(string propertyTypeAlias, bool value); /// - /// Get members based on a property search + /// Gets a list of Members based on a property search /// - /// - /// - /// - /// + /// Alias of the PropertyType to search for + /// Value to match + /// The type of match to make as . Default is + /// IEnumerable GetMembersByPropertyValue(string propertyTypeAlias, DateTime value, ValuePropertyMatchType matchType = ValuePropertyMatchType.Exact); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Services/IMembershipMemberService.cs b/src/Umbraco.Core/Services/IMembershipMemberService.cs index d4d865614a..801f88d9ac 100644 --- a/src/Umbraco.Core/Services/IMembershipMemberService.cs +++ b/src/Umbraco.Core/Services/IMembershipMemberService.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using Umbraco.Core.Models; -using Umbraco.Core.Models.EntityBase; using Umbraco.Core.Models.Membership; using Umbraco.Core.Persistence.Querying; @@ -13,12 +12,21 @@ namespace Umbraco.Core.Services /// Idea is to have this is an isolated interface so that it can be easily 'replaced' in the membership provider impl. /// public interface IMembershipMemberService : IMembershipMemberService, IMembershipRoleService - { + { + /// + /// Creates and persists a new Member + /// + /// Username of the Member to create + /// Email of the Member to create + /// which the Member should be based on + /// IMember CreateMemberWithIdentity(string username, string email, IMemberType memberType); } /// /// Defines part of the UserService/MemberService, which is specific to methods used by the membership provider. + /// The generic type is restricted to . The implementation of this interface uses + /// either for the MemberService or for the UserService. /// /// /// Idea is to have this is an isolated interface so that it can be easily 'replaced' in the membership provider impl. @@ -27,69 +35,124 @@ namespace Umbraco.Core.Services where T : class, IMembershipUser { /// - /// Returns the default member type alias + /// Gets the total number of Members or Users based on the count type /// - /// - string GetDefaultMemberType(); - - /// - /// Checks if a member with the username exists - /// - /// - /// - bool Exists(string username); - - /// - /// Creates and persists a new member - /// - /// - /// - /// - /// This value should be the encoded/encrypted/hashed value for the password that will be stored in the database - /// - /// - /// - T CreateWithIdentity(string username, string email, string rawPasswordValue, string memberTypeAlias); - - /// - /// Gets the member by the provider key - /// - /// - /// - T GetByProviderKey(object id); - - /// - /// Get a member by email - /// - /// - /// - T GetByEmail(string email); - - T GetByUsername(string login); - - void Delete(T membershipUser); - - void Save(T entity, bool raiseEvents = true); - - void Save(IEnumerable entities, bool raiseEvents = true); - - IEnumerable FindByEmail(string emailStringToMatch, int pageIndex, int pageSize, out int totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith); - - IEnumerable FindByUsername(string login, int pageIndex, int pageSize, out int totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith); - - /// - /// Gets the total number of members based on the count type - /// - /// + /// + /// The way the Online count is done is the same way that it is done in the MS SqlMembershipProvider - We query for any members + /// that have their last active date within the Membership.UserIsOnlineTimeWindow (which is in minutes). It isn't exact science + /// but that is how MS have made theirs so we'll follow that principal. + /// + /// to count by + /// with number of Members or Users for passed in type int GetCount(MemberCountType countType); /// - /// Gets a list of paged member data + /// Gets the default MemberType alias /// - /// - /// - /// - /// + /// By default we'll return the 'writer', but we need to check it exists. If it doesn't we'll + /// return the first type that is not an admin, otherwise if there's only one we will return that one. + /// Alias of the default MemberType + string GetDefaultMemberType(); + + /// + /// Checks if a Member with the username exists + /// + /// Username to check + /// True if the Member exists otherwise False + bool Exists(string username); + + /// + /// Creates and persists a new + /// + /// An can be of type or + /// Username of the to create + /// Email of the to create + /// This value should be the encoded/encrypted/hashed value for the password that will be stored in the database + /// Alias of the Type + /// + T CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias); + + /// + /// Gets an by its provider key + /// + /// An can be of type or + /// Id to use for retrieval + /// + T GetByProviderKey(object id); + + /// + /// Get an by email + /// + /// An can be of type or + /// Email to use for retrieval + /// + T GetByEmail(string email); + + /// + /// Get an by username + /// + /// An can be of type or + /// Username to use for retrieval + /// + T GetByUsername(string username); + + /// + /// Deletes an + /// + /// An can be of type or + /// or to Delete + void Delete(T membershipUser); + + /// + /// Saves an + /// + /// An can be of type or + /// or to Save + /// Optional parameter to raise events. + /// Default is True otherwise set to False to not raise events + void Save(T entity, bool raiseEvents = true); + + /// + /// Saves a list of objects + /// + /// An can be of type or + /// to save + /// Optional parameter to raise events. + /// Default is True otherwise set to False to not raise events + void Save(IEnumerable entities, bool raiseEvents = true); + + /// + /// Finds a list of objects by a partial email string + /// + /// An can be of type or + /// Partial email string to match + /// Current page index + /// Size of the page + /// Total number of records found (out) + /// The type of match to make as . Default is + /// + IEnumerable FindByEmail(string emailStringToMatch, int pageIndex, int pageSize, out int totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith); + + /// + /// Finds a list of objects by a partial username + /// + /// An can be of type or + /// Partial username to match + /// Current page index + /// Size of the page + /// Total number of records found (out) + /// The type of match to make as . Default is + /// + IEnumerable FindByUsername(string login, int pageIndex, int pageSize, out int totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith); + + /// + /// Gets a list of paged objects + /// + /// An can be of type or + /// Current page index + /// Size of the page + /// Total number of records found (out) + /// IEnumerable GetAll(int pageIndex, int pageSize, out int totalRecords); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Services/IMembershipUserService.cs b/src/Umbraco.Core/Services/IMembershipUserService.cs index 86dc09d225..182d08f9bd 100644 --- a/src/Umbraco.Core/Services/IMembershipUserService.cs +++ b/src/Umbraco.Core/Services/IMembershipUserService.cs @@ -10,6 +10,16 @@ namespace Umbraco.Core.Services /// public interface IMembershipUserService : IMembershipMemberService { + /// + /// Creates and persists a new User + /// + /// The user will be saved in the database and returned with an Id. + /// This method is convenient when you need to perform operations, which needs the + /// Id of the user once its been created. + /// Username of the User to create + /// Email of the User to create + /// which the User should be based on + /// IUser CreateUserWithIdentity(string username, string email, IUserType userType); } } \ No newline at end of file diff --git a/src/Umbraco.Core/Services/MemberService.cs b/src/Umbraco.Core/Services/MemberService.cs index ecf2874ea6..8a8e99f255 100644 --- a/src/Umbraco.Core/Services/MemberService.cs +++ b/src/Umbraco.Core/Services/MemberService.cs @@ -1,21 +1,15 @@ using System; using System.Collections.Generic; -using System.Runtime.CompilerServices; using System.Threading; using System.Web.Security; using System.Xml.Linq; -using System.Xml.Linq; -using Umbraco.Core.Auditing; using Umbraco.Core.Configuration; using Umbraco.Core.Events; -using Umbraco.Core.Events; using Umbraco.Core.Models; -using Umbraco.Core.Models.EntityBase; using Umbraco.Core.Models.Membership; using Umbraco.Core.Models.Rdbms; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Querying; -using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Persistence.UnitOfWork; using System.Linq; @@ -23,7 +17,6 @@ using Umbraco.Core.Security; namespace Umbraco.Core.Services { - /// /// Represents the MemberService. /// @@ -77,9 +70,11 @@ namespace Umbraco.Core.Services #region IMemberService Implementation /// - /// Get the default member type from the database - first check if the type "Member" is there, if not choose the first one found + /// Gets the default MemberType alias /// - /// + /// By default we'll return the 'writer', but we need to check it exists. If it doesn't we'll + /// return the first type that is not an admin, otherwise if there's only one we will return that one. + /// Alias of the default MemberType public string GetDefaultMemberType() { using (var repository = _repositoryFactory.CreateMemberTypeRepository(_uowProvider.GetUnitOfWork())) @@ -101,10 +96,10 @@ namespace Umbraco.Core.Services } /// - /// Checks if a member with the username exists + /// Checks if a Member with the username exists /// - /// - /// + /// Username to check + /// True if the Member exists otherwise False public bool Exists(string username) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -116,11 +111,10 @@ namespace Umbraco.Core.Services /// /// This is simply a helper method which essentially just wraps the MembershipProvider's ChangePassword method /// - /// The member to save the password for - /// - /// - /// This method exists so that Umbraco developers can use one entry point to create/update members if they choose to. - /// + /// This method exists so that Umbraco developers can use one entry point to create/update + /// Members if they choose to. + /// The Member to save the password for + /// The password to encrypt and save public void SavePassword(IMember member, string password) { if (member == null) throw new ArgumentNullException("member"); @@ -148,10 +142,10 @@ namespace Umbraco.Core.Services } /// - /// Checks if a member with the id exists + /// Checks if a Member with the id exists /// - /// - /// + /// Id of the Member + /// True if the Member exists otherwise False public bool Exists(int id) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -161,10 +155,10 @@ namespace Umbraco.Core.Services } /// - /// Gets a Member by its integer Id + /// Gets a Member by its integer id /// - /// - /// + /// Id + /// public IMember GetById(int id) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -174,14 +168,12 @@ namespace Umbraco.Core.Services } /// - /// Gets a Member by its Guid key + /// Gets a Member by the unique key /// - /// - /// The guid key corresponds to the unique id in the database - /// and the user id in the membership provider. - /// - /// - /// + /// The guid key corresponds to the unique id in the database + /// and the user id in the membership provider. + /// Id + /// public IMember GetByKey(Guid id) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -193,10 +185,10 @@ namespace Umbraco.Core.Services } /// - /// Gets a list of Members by their MemberType + /// Gets all Members for the specified MemberType alias /// - /// - /// + /// Alias of the MemberType + /// public IEnumerable GetMembersByMemberType(string memberTypeAlias) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -208,10 +200,10 @@ namespace Umbraco.Core.Services } /// - /// Gets a list of Members by their MemberType + /// Gets all Members for the MemberType id /// - /// - /// + /// Id of the MemberType + /// public IEnumerable GetMembersByMemberType(int memberTypeId) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -224,10 +216,10 @@ namespace Umbraco.Core.Services } /// - /// Gets a list of Members by the MemberGroup they are part of + /// Gets all Members within the specified MemberGroup name /// - /// - /// + /// Name of the MemberGroup + /// public IEnumerable GetMembersByGroup(string memberGroupName) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -237,10 +229,11 @@ namespace Umbraco.Core.Services } /// - /// Gets a list of all Members + /// Gets all Members with the ids specified /// - /// - /// + /// If no Ids are specified all Members will be retrieved + /// Optional list of Member Ids + /// public IEnumerable GetAllMembers(params int[] ids) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -249,6 +242,10 @@ namespace Umbraco.Core.Services } } + /// + /// Delete Members of the specified MemberType id + /// + /// Id of the MemberType public void DeleteMembersOfType(int memberTypeId) { using (new WriteLock(Locker)) @@ -272,6 +269,15 @@ namespace Umbraco.Core.Services } } + /// + /// Finds Members based on their display name + /// + /// Display name to match + /// Current page index + /// Size of the page + /// Total number of records found (out) + /// The type of match to make as . Default is + /// public IEnumerable FindMembersByDisplayName(string displayNameToMatch, int pageIndex, int pageSize, out int totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith) { var uow = _uowProvider.GetUnitOfWork(); @@ -314,14 +320,14 @@ namespace Umbraco.Core.Services } /// - /// Does a search for members that contain the specified string in their email address + /// Finds a list of objects by a partial email string /// - /// - /// - /// - /// - /// - /// + /// Partial email string to match + /// Current page index + /// Size of the page + /// Total number of records found (out) + /// The type of match to make as . Default is + /// public IEnumerable FindByEmail(string emailStringToMatch, int pageIndex, int pageSize, out int totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith) { var uow = _uowProvider.GetUnitOfWork(); @@ -354,6 +360,15 @@ namespace Umbraco.Core.Services } } + /// + /// Finds a list of objects by a partial username + /// + /// Partial username to match + /// Current page index + /// Size of the page + /// Total number of records found (out) + /// The type of match to make as . Default is + /// public IEnumerable FindByUsername(string login, int pageIndex, int pageSize, out int totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith) { var uow = _uowProvider.GetUnitOfWork(); @@ -387,12 +402,12 @@ namespace Umbraco.Core.Services } /// - /// Gets a list of Members with a certain string property value + /// Gets a list of Members based on a property search /// - /// - /// - /// - /// + /// Alias of the PropertyType to search for + /// Value to match + /// The type of match to make as . Default is + /// public IEnumerable GetMembersByPropertyValue(string propertyTypeAlias, string value, StringPropertyMatchType matchType = StringPropertyMatchType.Exact) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -443,12 +458,12 @@ namespace Umbraco.Core.Services } /// - /// Gets a list of Members with a certain integer property value + /// Gets a list of Members based on a property search /// - /// - /// - /// - /// + /// Alias of the PropertyType to search for + /// Value to match + /// The type of match to make as . Default is + /// public IEnumerable GetMembersByPropertyValue(string propertyTypeAlias, int value, ValuePropertyMatchType matchType = ValuePropertyMatchType.Exact) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -502,11 +517,11 @@ namespace Umbraco.Core.Services } /// - /// Gets a list of Members with a certain boolean property value + /// Gets a list of Members based on a property search /// - /// - /// - /// + /// Alias of the PropertyType to search for + /// Value to match + /// public IEnumerable GetMembersByPropertyValue(string propertyTypeAlias, bool value) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -523,12 +538,12 @@ namespace Umbraco.Core.Services } /// - /// Gets a list of Members with a certain date time property value + /// Gets a list of Members based on a property search /// - /// - /// - /// - /// + /// Alias of the PropertyType to search for + /// Value to match + /// The type of match to make as . Default is + /// public IEnumerable GetMembersByPropertyValue(string propertyTypeAlias, DateTime value, ValuePropertyMatchType matchType = ValuePropertyMatchType.Exact) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -586,15 +601,15 @@ namespace Umbraco.Core.Services #region IMembershipMemberService Implementation /// - /// Returns the count of members based on the countType + /// Gets the total number of Members based on the count type /// - /// - /// /// /// The way the Online count is done is the same way that it is done in the MS SqlMembershipProvider - We query for any members /// that have their last active date within the Membership.UserIsOnlineTimeWindow (which is in minutes). It isn't exact science /// but that is how MS have made theirs so we'll follow that principal. /// + /// to count by + /// with number of Members for passed in type public int GetCount(MemberCountType countType) { using (var repository = _repositoryFactory.CreateMemberRepository(_uowProvider.GetUnitOfWork())) @@ -635,6 +650,13 @@ namespace Umbraco.Core.Services } + /// + /// Gets a list of paged objects + /// + /// Current page index + /// Size of the page + /// Total number of records found (out) + /// public IEnumerable GetAll(int pageIndex, int pageSize, out int totalRecords) { var uow = _uowProvider.GetUnitOfWork(); @@ -644,23 +666,32 @@ namespace Umbraco.Core.Services } } - public int Count(string contentTypeAlias = null) + /// + /// Gets the count of Members by an optional MemberType alias + /// + /// If no alias is supplied then the count for all Member will be returned + /// Optional alias for the MemberType when counting number of Members + /// with number of Members + public int Count(string memberTypeAlias = null) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateMemberRepository(uow)) { - return repository.Count(contentTypeAlias); + return repository.Count(memberTypeAlias); } } /// - /// Creates a member object + /// Creates an object without persisting it /// - /// - /// - /// - /// - /// + /// This method is convenient for when you need to add properties to a new Member + /// before persisting it in order to limit the amount of times its saved. + /// Also note that the returned will not have an Id until its saved. + /// Username of the Member to create + /// Email of the Member to create + /// Name of the Member to create + /// Alias of the MemberType the Member should be based on + /// public IMember CreateMember(string username, string email, string name, string memberTypeAlias) { var memberType = FindMemberTypeByAlias(memberTypeAlias); @@ -668,13 +699,16 @@ namespace Umbraco.Core.Services } /// - /// Creates a new member object + /// Creates an object without persisting it /// - /// - /// - /// - /// - /// + /// This method is convenient for when you need to add properties to a new Member + /// before persisting it in order to limit the amount of times its saved. + /// Also note that the returned will not have an Id until its saved. + /// Username of the Member to create + /// Email of the Member to create + /// Name of the Member to create + /// MemberType the Member should be based on + /// public IMember CreateMember(string username, string email, string name, IMemberType memberType) { var member = new Member(name, email.ToLower().Trim(), username, memberType); @@ -685,13 +719,15 @@ namespace Umbraco.Core.Services } /// - /// Creates a member with an Id + /// Creates and persists a Member /// - /// - /// - /// - /// - /// + /// Using this method will persist the Member object before its returned + /// meaning that it will have an Id available (unlike the CreateMember method) + /// Username of the Member to create + /// Email of the Member to create + /// Name of the Member to create + /// Alias of the MemberType the Member should be based on + /// public IMember CreateMemberWithIdentity(string username, string email, string name, string memberTypeAlias) { var memberType = FindMemberTypeByAlias(memberTypeAlias); @@ -699,49 +735,65 @@ namespace Umbraco.Core.Services } /// - /// Creates a member with an Id, the username will be used as their name + /// Creates and persists a Member /// - /// - /// - /// - /// + /// Using this method will persist the Member object before its returned + /// meaning that it will have an Id available (unlike the CreateMember method) + /// Username of the Member to create + /// Email of the Member to create + /// MemberType the Member should be based on + /// public IMember CreateMemberWithIdentity(string username, string email, IMemberType memberType) { return CreateMemberWithIdentity(username, email, username, memberType); } /// - /// Creates a member with an Id + /// Creates and persists a Member /// - /// - /// - /// - /// - /// + /// Using this method will persist the Member object before its returned + /// meaning that it will have an Id available (unlike the CreateMember method) + /// Username of the Member to create + /// Email of the Member to create + /// Name of the Member to create + /// MemberType the Member should be based on + /// public IMember CreateMemberWithIdentity(string username, string email, string name, IMemberType memberType) { return CreateMemberWithIdentity(username, email, name, "", memberType); } /// - /// Creates and persists a new Member + /// Creates and persists a new /// - /// - /// - /// - /// - /// - IMember IMembershipMemberService.CreateWithIdentity(string username, string email, string rawPasswordValue, string memberTypeAlias) + /// An can be of type or + /// Username of the to create + /// Email of the to create + /// This value should be the encoded/encrypted/hashed value for the password that will be stored in the database + /// Alias of the Type + /// + IMember IMembershipMemberService.CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias) { var memberType = FindMemberTypeByAlias(memberTypeAlias); - return CreateMemberWithIdentity(username, email, username, rawPasswordValue, memberType); + return CreateMemberWithIdentity(username, email, username, passwordValue, memberType); } - private IMember CreateMemberWithIdentity(string username, string email, string name, string rawPasswordValue, IMemberType memberType) + /// + /// Creates and persists a Member + /// + /// Using this method will persist the Member object before its returned + /// meaning that it will have an Id available (unlike the CreateMember method) + /// Username of the Member to create + /// Email of the Member to create + /// Name of the Member to create + /// This value should be the encoded/encrypted/hashed value for the password that will be stored in the database + /// MemberType the Member should be based on + /// + private IMember CreateMemberWithIdentity(string username, string email, string name, string passwordValue, IMemberType memberType) { if (memberType == null) throw new ArgumentNullException("memberType"); - var member = new Member(name, email.ToLower().Trim(), username, rawPasswordValue, memberType); + var member = new Member(name, email.ToLower().Trim(), username, passwordValue, memberType); if (Saving.IsRaisedEventCancelled(new SaveEventArgs(member), this)) { @@ -771,13 +823,10 @@ namespace Umbraco.Core.Services } /// - /// Gets a Member by its Id + /// Gets an by its provider key /// - /// - /// The Id should be an integer or Guid. - /// - /// - /// + /// Id to use for retrieval + /// public IMember GetByProviderKey(object id) { var asGuid = id.TryConvertTo(); @@ -795,10 +844,10 @@ namespace Umbraco.Core.Services } /// - /// Gets a Member by its Email + /// Get an by email /// - /// - /// + /// Email to use for retrieval + /// public IMember GetByEmail(string email) { var uow = _uowProvider.GetUnitOfWork(); @@ -812,16 +861,16 @@ namespace Umbraco.Core.Services } /// - /// Gets a Member by its Username + /// Get an by username /// - /// - /// - public IMember GetByUsername(string userName) + /// Username to use for retrieval + /// + public IMember GetByUsername(string username) { var uow = _uowProvider.GetUnitOfWork(); using (var repository = _repositoryFactory.CreateMemberRepository(uow)) { - var query = Query.Builder.Where(x => x.Username.Equals(userName)); + var query = Query.Builder.Where(x => x.Username.Equals(username)); var member = repository.GetByQuery(query).FirstOrDefault(); return member; @@ -829,9 +878,9 @@ namespace Umbraco.Core.Services } /// - /// Deletes a Member + /// Deletes an /// - /// + /// to Delete public void Delete(IMember member) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs(member), this)) @@ -846,12 +895,13 @@ namespace Umbraco.Core.Services Deleted.RaiseEvent(new DeleteEventArgs(member, false), this); } - + /// - /// Saves an updated Member + /// Saves an /// - /// - /// + /// to Save + /// Optional parameter to raise events. + /// Default is True otherwise set to False to not raise events public void Save(IMember entity, bool raiseEvents = true) { if (raiseEvents) @@ -860,7 +910,6 @@ namespace Umbraco.Core.Services { return; } - } var uow = _uowProvider.GetUnitOfWork(); @@ -881,6 +930,12 @@ namespace Umbraco.Core.Services Saved.RaiseEvent(new SaveEventArgs(entity, false), this); } + /// + /// Saves a list of objects + /// + /// to save + /// Optional parameter to raise events. + /// Default is True otherwise set to False to not raise events public void Save(IEnumerable entities, bool raiseEvents = true) { var asArray = entities.ToArray(); @@ -1261,7 +1316,5 @@ namespace Umbraco.Core.Services return new Member(name, email, username, password, memType); } - - } } \ No newline at end of file