public void UpdateLoggedInUser(User user)
        {
            // Get the user's entry from the list if it exists already.
            var userEntry = _loggedInUsers.Where(u => u.Email.ToLower() == user.Email.ToLower()).FirstOrDefault();

            if (userEntry == null)
            {
                _loggedInUsers.Add(user);
            }
        }
        private void CreateAdminUser()
        {
            var adminId = Guid.NewGuid();
            string password = this._securityManager.EncodePassword(Resources.DefaultValues.AdministratorPassword);
            var admin = new User(adminId, Resources.DefaultValues.AdministratorEmail, Resources.DefaultValues.AdministratorName);
            admin.PreferredCulture = StrixPlatform.DefaultCultureCode;
            this._dataSource.Save(admin);

            var security = new UserSecurity(admin.Id);
            security.Password = password;
            security.Approved = true;
            this._dataSource.Save(security);

            var session = new UserSessionStorage(admin.Id);
            this._dataSource.Save(session);

            var userRole = new UserInRole(this._adminRole, admin.Id, DateTime.Now, null);
            admin.Roles = new List<UserInRole>() { userRole };
        }
        public User Create(string name, string email, string preferredCulture, string password, bool isApproved, bool acceptedTerms, string registrationComment)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentNullException("email");
            }

            this.CheckEmailAvailable(email);
            User user = this._dataSource.Query<User>().FirstOrDefault(u => u.Email.ToLower() == email.ToLower());

            if (user == null)
            {
                CheckPassword(password);
                var encodedPassword = this._securityManager.EncodePassword(password);

                user = new User(Guid.NewGuid(), email, name);
                user.PreferredCulture = string.IsNullOrWhiteSpace(preferredCulture) ? StrixPlatform.CurrentCultureCode : preferredCulture;
                user.DateAcceptedTerms = acceptedTerms ? (DateTime?)DateTime.Now : null;

                var security = new UserSecurity(user.Id);
                security.Password = encodedPassword;
                security.Approved = isApproved || StrixMembership.Configuration.Registration.AutoApproveUsers;
                security.RegistrationComment = registrationComment;

                var session = new UserSessionStorage(user.Id);

                user = this._dataSource.Save(user);
                security = this._dataSource.Save(security);
                session = this._dataSource.Save(session);

                if (security == null || session == null)
                {
                    user = null;
                }
            }

            if (user != null)
            {
                var args = new Dictionary<string, object>();
                args.Add("Id", user.Id);
                args.Add("UserName", user.Name);
                args.Add("UserEmail", user.Email);
                StrixPlatform.RaiseEvent<GeneralEvent>(new GeneralEvent("UserCreateEvent", args));
            }

            return user;
        }
        public void InitAdminUser()
        {
            var saveChanges = false;
            this._adminUser = this._dataSource.Query<User>("Roles.GroupRole.Role").FirstOrDefault(u => u.Email.ToLower() == Resources.DefaultValues.AdministratorEmail.ToLower());

            if (this._adminUser == null)
            {
                this.CreateAdminUser();
                saveChanges = true;
            }
            else if (!this._adminUser.Roles.Any(r => r.GroupRole.Role.Name.ToLower() == PlatformConstants.ADMINROLE.ToLower()))
            {
                var userRole = new UserInRole(this._adminRole, this._adminUser.Id, DateTime.Now, null);
                this._adminUser.Roles.Add(userRole);
                saveChanges = true;
            }

            if (saveChanges)
            {
                this._dataSource.SaveChanges();
            }
        }