/// <summary>
        ///  Delete an organization by id, this has the side effect of
        /// de-activating all users of that organization.
        /// </summary>
        /// <param name="organizationId">The id of the org to delete.</param>
        public static void Delete(int organizationId)
        {
            UserHelper.DeactivateUsersOfOrg(organizationId);
            var org = _orgDao.GetFirst("Id", organizationId);

            org.Active = false;
            _orgWriteDao.Update(org);
        }
Exemple #2
0
        /// <summary>
        /// Update an existing user and all fields passed in will overwrite existing values.
        /// </summary>
        /// <param name="userName">UserName for the user, existing or desired.</param>
        /// <param name="hashedPassword">The pre-hashed password for this user.</param>
        /// <param name="email">The email address of this user.</param>
        /// <param name="name">The actual name of this user.</param>
        /// <param name="roles">A comma seperated list of roles assigned to this user.</param>
        /// <param name="active">The users active status</param>
        /// <param name="affiliation">The company or org the user is associated with.</param>
        /// <param name="confirmedEmail">Has the user's email address been confirmed</param>
        public static User UpdateUser(string userName, string hashedPassword, string email,
                                      string name, string roles, int organization, bool?active,
                                      string affiliation = null, bool?confirmedEmail = false)
        {
            // Determine if this is new user or an update
            User userAccount = GetUser(userName);

            // If a user was not found, create a new user object
            if (userAccount == null)
            {
                throw new ArgumentException("No record found for user name [" + userName + "].");
            }

            // Apply the information to the account
            // Check for an empty/null string, we don't want them in the db.
            if (StringHelper.IsNonBlank(email))
            {
                userAccount.Email = email;
            }
            if (StringHelper.IsNonBlank(name))
            {
                userAccount.Name = name;
            }
            if (StringHelper.IsNonBlank(roles))
            {
                userAccount.Roles = roles;
            }
            if (confirmedEmail.HasValue)
            {
                userAccount.EmailConfirmed = confirmedEmail.Value;
            }

            if (affiliation != null)
            {
                userAccount.Affiliation = affiliation;
            }

            // Only overwrite password if the new one is non-blank
            if (StringHelper.IsNonBlank(hashedPassword))
            {
                userAccount.Password = hashedPassword;
            }

            if (organization != Organization.NO_UPDATE)
            {
                userAccount.SetOrganization(organization);
            }

            if (active.HasValue)
            {
                userAccount.Active = active.Value;
            }

            // Save the information to the database
            _userDao.Update(userAccount);

            return(userAccount);
        }
Exemple #3
0
        /// <summary>
        /// Update an existing user and all fields passed in will overwrite existing values.
        /// </summary>
        /// <param name="userName">UserName for the user, existing or desired.</param>
        /// <param name="hashedPassword">The pre-hashed password for this user.</param>
        /// <param name="email">The email address of this user.</param>
        /// <param name="name">The actual name of this user.</param>
        /// <param name="roles">A comma seperated list of roles assigned to this user.</param>
        public static User UpdateUser(string userName, string hashedPassword, string email,
                                      string name, string roles)
        {
            // Determine if this is new user or an update
            User userAccount = GetUser(userName);

            // If a user was not found, create a new user object
            if (userAccount == null)
            {
                throw new ArgumentException("No record found for user name [" + userName + "].");
            }

            // Apply the information to the account
            // Check for an empty/null string, we don't want them in the db.
            if (StringHelper.IsNonBlank(email))
            {
                userAccount.Email = email;
            }
            if (StringHelper.IsNonBlank(name))
            {
                userAccount.Name = name;
            }
            if (StringHelper.IsNonBlank(roles))
            {
                userAccount.Roles = roles;
            }

            // Only overwrite password if the new one is non-blank
            if (StringHelper.IsNonBlank(hashedPassword))
            {
                userAccount.Password = hashedPassword;
            }

            // Save the information to the database
            _userDao.Update(userAccount);

            return(userAccount);
        }