Exemplo n.º 1
0
        public void ProjectModelToContent(MemberTypeBase model, IMember content)
        {
            var type = model.GetType();
            MemberTypeRegistration reg;

            if (_memberTypeModule.TryGetMemberType(type, out reg) && (reg.ClrType == type || reg.ClrType.Inherits(type)))
            {
                SetMemberSpecificProperties(model, content);
                MapModelToContent(content, model, reg);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates an existing IContent item with the current values of the model
        /// </summary>
        /// <returns></returns>
        private IMember UpdateContent(MemberTypeBase model, ContentTypeRegistration registration)
        {
            if (model.NodeDetails == null || model.NodeDetails.UmbracoId == -1)
            {
                throw new ArgumentException("Can't update content for a model with no ID. Try calling CreateContent instead. Check that the NodeDetails.UmbracoId property is set before calling UpdateContent.");
            }
            var node = ApplicationContext.Current.Services.MemberService.GetById(model.NodeDetails.UmbracoId);

            SetMemberSpecificProperties(model, node);
            MapModelToContent(node, model, registration);
            return(node);
        }
Exemplo n.º 3
0
 private void SetMemberSpecificProperties(MemberTypeBase model, IMember node)
 {
     node.Email                  = model.Email;
     node.Username               = model.Username;
     node.Name                   = model.Name;
     node.Comments               = model.Comments;
     node.IsApproved             = model.IsApproved;
     node.IsLockedOut            = model.IsLockedOut;
     node.LastLockoutDate        = model.LastLockoutDate;
     node.LastLoginDate          = model.LastLoginDate;
     node.LastPasswordChangeDate = model.LastPasswordChangeDate;
     node.PasswordQuestion       = model.PasswordQuestion;
     node.RawPasswordAnswerValue = model.PasswordAnswer;
 }
Exemplo n.º 4
0
 private void GetMemberSpecificProperties(MemberTypeBase memberTypeBase, Umbraco.Web.PublishedCache.MemberPublishedContent content)
 {
     memberTypeBase.Email                  = content.Email;
     memberTypeBase.Username               = content.UserName;
     memberTypeBase.Name                   = content.Name;
     memberTypeBase.Comments               = content.Comments;
     memberTypeBase.IsApproved             = content.IsApproved;
     memberTypeBase.IsLockedOut            = content.IsLockedOut;
     memberTypeBase.LastLockoutDate        = content.LastLockoutDate;
     memberTypeBase.LastLoginDate          = content.LastLoginDate;
     memberTypeBase.LastPasswordChangeDate = content.LastPasswordChangedDate;
     memberTypeBase.PasswordQuestion       = content.PasswordQuestion;
     memberTypeBase.PasswordAnswer         = "[redacted from published version]";
     memberTypeBase.FailedPasswordAttempts = -1;
 }
Exemplo n.º 5
0
 private void GetMemberSpecificProperties(MemberTypeBase memberTypeBase, IMember content)
 {
     memberTypeBase.Email                  = content.Email;
     memberTypeBase.Username               = content.Username;
     memberTypeBase.Name                   = content.Name;
     memberTypeBase.Comments               = content.Comments;
     memberTypeBase.IsApproved             = content.IsApproved;
     memberTypeBase.IsLockedOut            = content.IsLockedOut;
     memberTypeBase.LastLockoutDate        = content.LastLockoutDate;
     memberTypeBase.LastLoginDate          = content.LastLoginDate;
     memberTypeBase.LastPasswordChangeDate = content.LastPasswordChangeDate;
     memberTypeBase.PasswordQuestion       = content.PasswordQuestion;
     memberTypeBase.PasswordAnswer         = content.RawPasswordAnswerValue;
     memberTypeBase.FailedPasswordAttempts = content.FailedPasswordAttempts;
 }
Exemplo n.º 6
0
        public IMember ConvertToContent(MemberTypeBase model)
        {
            var contentId = model.NodeDetails.UmbracoId;
            MemberTypeRegistration registration;

            if (!_memberTypeModule.TryGetMemberType(model.GetType(), out registration))
            {
                throw new CodeFirstException("Member type not registered. Type: " + model.GetType());
            }

            //Create or update object
            if (contentId == -1)
            {
                return(CreateContent(model, registration));
            }
            else
            {
                return(UpdateContent(model, registration));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// <para>Creates an IMember populated with the current values of the model</para>
        /// </summary>
        private IMember CreateContent(MemberTypeBase model, ContentTypeRegistration registration)
        {
            if (model.Name == null)
            {
                throw new CodeFirstException("Name must be set to create a member");
            }
            if (model.Username == null)
            {
                throw new CodeFirstException("Username must be set to create a member");
            }
            if (model.Email == null)
            {
                throw new CodeFirstException("Email must be set to create a member");
            }

            //Get the type alias and create the content
            var typeAlias = registration.Alias;
            var node      = ApplicationContext.Current.Services.MemberService.CreateMemberWithIdentity(model.Username, model.Email, model.Name, typeAlias);

            SetMemberSpecificProperties(model, node);
            MapModelToContent(node, model, registration);
            return(node);
        }