public void DeleteUser(User userToDelete)
 {
     NHibernateSessionFactory.Session.Delete(userToDelete);
 }
        /// <summary>
        /// Create a MembershipUser object from a user object.
        /// </summary>
        /// <param name="u">User Object.</param>
        /// <returns>MembershipUser object.</returns>
        private MembershipUser GetUserFromObject(User u)
        {
            var creationDate = (DateTime)u.CreationDate;
            var lastLoginDate = new DateTime();
            if (u.LastLoginDate != null)
            {
                lastLoginDate = (DateTime)u.LastLoginDate;
            }
            var lastActivityDate = new DateTime();
            if (u.LastActivityDate != null)
            {
                lastActivityDate = (DateTime)u.LastActivityDate;
            }
            var lastPasswordChangedDate = new DateTime();
            if (u.LastPasswordChangedDate != null)
            {
                lastPasswordChangedDate = (DateTime)u.LastPasswordChangedDate;
            }
            var lastLockedOutDate = new DateTime();
            if (u.LastLockedOutDate != null)
            {
                lastLockedOutDate = (DateTime)u.LastLockedOutDate;
            }

            return new MembershipUser(Name, u.Username, u.Id, u.Email, u.PasswordQuestion, u.Comment,
                u.IsApproved, u.IsLockedOut, creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockedOutDate);
        }
 public void SaveUser(User userToSave)
 {
     NHibernateSessionFactory.Session.SaveOrUpdate(userToSave);
 }
        /// <summary>
        /// Create a new user.
        /// </summary>
        /// <param name="username">User name.</param>
        /// <param name="password">Password.</param>
        /// <param name="email">Email address.</param>
        /// <param name="passwordQuestion">Security quesiton for password.</param>
        /// <param name="passwordAnswer">Security quesiton answer for password.</param>
        /// <param name="isApproved"></param>
        /// <param name="brandId">Brand user belongs to</param>
        /// <param name="status"></param>
        /// <returns>MembershipUser</returns>
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object brandId, out MembershipCreateStatus status)
        {
            var args = new ValidatePasswordEventArgs(username, password, true);
            OnValidatingPassword(args);
            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }
            if ((RequiresUniqueEmail && (GetUserNameByEmail(email) != String.Empty)))
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }
            MembershipUser membershipUser = GetUser(username, false);
            if (membershipUser == null)
            {
                User user = new User
                         {
                             Username = username,
                             ApplicationName = _applicationName,
                             Password = EncodePassword(password),
                             Email = email,
                             PasswordQuestion = passwordQuestion,
                             PasswordAnswer = EncodePassword(passwordAnswer),
                             IsApproved = isApproved,
                             Comment = String.Empty,
                             CreationDate = DateTime.Now,
                             Brand = new Brand((int)brandId)
                         };
                try
                {
                    UserRepo.SaveUser(user);
                    status = MembershipCreateStatus.Success;
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Error processing membership data - {0}", ex.Message);
                    throw new MemberAccessException("Error processing membership data - " + ex.Message);
                }
                return GetUser(username, false);
            }

            status = MembershipCreateStatus.DuplicateUserName;

            return null;
        }