Example #1
0
 /// <summary>
 /// Gets all members
 /// </summary>
 /// <returns>List of all members</returns>
 public static IEnumerable <MemberTypeBase> GetAllMembers()
 {
     foreach (Member member in Member.GetAllAsList())
     {
         MemberTypeBase m = MemberTypeResolver.Instance.GetTyped <MemberTypeBase>(member);
         if (m != null)
         {
             yield return(m);
         }
     }
 }
Example #2
0
        /// <summary>
        /// Gets members by name
        /// </summary>
        /// <param name="usernameToMatch">Part or full username (login name)</param>
        /// <param name="matchByNameInsteadOfLogin">If true, uses it compares usernameToMatch with name instead of login name</param>
        /// <returns></returns>
        public static List <MemberTypeBase> GetMembersByName(string usernameToMatch, bool matchByNameInsteadOfLogin)
        {
            List <MemberTypeBase> retVal = new List <MemberTypeBase>();

            Member[] members = Member.GetMemberByName(usernameToMatch, matchByNameInsteadOfLogin);

            foreach (Member member in members)
            {
                MemberTypeBase m = MemberTypeResolver.Instance.GetTyped <MemberTypeBase>(member);
                if (m != null)
                {
                    retVal.Add(m);
                }
            }

            return(retVal);
        }
Example #3
0
        /// <summary>
        /// Gets member by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static MemberTypeBase GetMemberById(int id)
        {
            MemberTypeBase retVal = null;
            Member         member = null;

            try
            {
                member = new Member(id);
            }
            catch
            {
                // member is not found
            }

            if (member != null)
            {
                retVal = MemberTypeResolver.Instance.GetTyped <MemberTypeBase>(member);
            }

            return(retVal);
        }
        public void Intercept(IInvocation invocation)
        {
            MemberTypeBase memberType = (MemberTypeBase)invocation.InvocationTarget;

            string propertyName = invocation.Method.GetPropertyName();

            if (invocation.Method.IsGetter())
            {
                if (memberType[propertyName] == null)
                {
                    Type         typeDocType = MemberTypeManager.GetMemberTypeType(memberType.Source.ContentType.Alias);
                    PropertyInfo propInfo    = typeDocType.GetProperty(propertyName);

                    object value = null;
                    try
                    {
                        value = MemberHelper.GetPropertyValue(memberType.Source, propInfo);
                        memberType[propertyName] = value;
                    }
                    catch (Exception exc)
                    {
                        throw new Exception(string.Format("Cannot set the value of a Member type property {0}.{1} (member type: {2}) to value: '{3}' (value type: {4}). Error: {5}",
                                                          typeDocType.Name, propInfo.Name, propInfo.PropertyType.FullName,
                                                          value, value != null ? value.GetType().FullName : "null", exc.Message));
                    }
                }

                invocation.ReturnValue = memberType[propertyName];
                if (invocation.ReturnValue == null && invocation.Method.ReturnType == typeof(bool))
                {
                    invocation.ReturnValue = false;
                }
            }
            else
            {
                memberType[propertyName] = invocation.Arguments[0];
            }
        }
Example #5
0
        /// <summary>
        /// Updates or adds the member. If member already exists, it updates it.
        /// If member doesn't exists, it creates new member.
        /// </summary>
        /// <param name="member">Member to update/add</param>
        /// <param name="user">User used for add or updating the content</param>
        private static void Save(MemberTypeBase member, User user)
        {
            if (user == null)
            {
                throw new Exception("User cannot be null!");
            }

            if (string.IsNullOrEmpty(member.LoginName))
            {
                throw new Exception("Member Login Name cannot be empty");
            }

            MemberType memberType = MemberTypeManager.GetMemberType(member.GetType());

            Member umember;

            if (member.Id == 0) // member is new so create Member
            {
                umember = Member.MakeNew(member.LoginName, member.Email, memberType, user);

                // reload
                umember          = Member.GetMemberFromLoginName(member.LoginName);
                umember.Password = member.Password;
                member.Id        = umember.Id;
            }
            else // member already exists, so load it
            {
                umember = new Member(member.Id);
            }

            umember.Email     = member.Email;
            umember.LoginName = member.LoginName;

            foreach (PropertyInfo propInfo in member.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                DocumentTypePropertyAttribute propAttr = Util.GetAttribute <DocumentTypePropertyAttribute>(propInfo);
                if (propAttr == null)
                {
                    continue; // skip this property - not part of a Document Type
                }

                string propertyName;
                string propertyAlias;
                MemberTypeManager.ReadPropertyNameAndAlias(propInfo, propAttr, out propertyName, out propertyAlias);

                umbraco.cms.businesslogic.property.Property property = umember.getProperty(propertyAlias);
                if (property == null)
                {
                    throw new Exception(string.Format("Property '{0}' not found in this node: {1}. Content type: {2}.",
                                                      propertyAlias, member.Id, memberType.Alias));
                }

                if (ContentHelper.PropertyConvertors.ContainsKey(propInfo.PropertyType))
                {
                    property.Value = ContentHelper.PropertyConvertors[propInfo.PropertyType].ConvertValueWhenWrite(propInfo.GetValue(member, null));
                }
                else
                {
                    property.Value = propInfo.GetValue(member, null);
                }
            }

            umember.Save();
        }
Example #6
0
 /// <summary>
 /// Updates or adds the member using current user. If member already exists, it updates it.
 /// If member doesn't exists, it creates new member.
 /// </summary>
 /// <param name="member">Content item to update/add</param>
 public static void Save(MemberTypeBase member)
 {
     MemberHelper.Save(member, Util.GetAdminUser());
 }