Example #1
0
        /// <summary>
        /// Handles the Click event of the cmdUpdate control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void CmdUpdateClick(object sender, EventArgs e)
        {
            try
            {
                GetMembershipData(UserId);

                var user = (CustomMembershipUser)MembershipData;

                if (user != null)
                {
                    //user.IsApproved = Authorized.Checked;
                    user.Email       = Email.Text;
                    user.DisplayName = DisplayName.Text;
                    user.FirstName   = FirstName.Text;
                    user.LastName    = LastName.Text;
                    UserManager.UpdateUser(user);
                    OnAction(new ActionEventArgs {
                        Trigger = ActionTriggers.Save
                    });

                    UserCustomFieldManager.SaveCustomFieldValues(UserId, ctlUserCustomFields.Values);
                }
                ActionMessage.ShowSuccessMessage(GetLocalResourceObject("UpdateUserMessage").ToString());
            }
            catch
            {
                ActionMessage.ShowErrorMessage(LoggingManager.GetErrorMessageResource("UpdateUserError"));
            }
        }
Example #2
0
        /// <summary>
        /// Handles the Click event of the AddNewUser control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void AddNewUserClick(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            var password = chkRandomPassword.Checked ? Membership.GeneratePassword(7, 0) : Password.Text;

            var    createStatus = MembershipCreateStatus.Success;
            string resultMsg;

            var userIdText = UserName.Text;
            var emailText  = Email.Text;
            var isActive   = ActiveUser.Checked;

            try
            {
                var mu = Membership.CreateUser(userIdText, password, emailText);

                if (createStatus == MembershipCreateStatus.Success && mu != null)
                {
                    var profile = new WebProfile().GetProfile(mu.UserName);
                    profile.DisplayName = DisplayName.Text;
                    profile.FirstName   = FirstName.Text;
                    profile.LastName    = LastName.Text;
                    profile.Save();

                    //auto assign user to roles
                    var roles = RoleManager.GetAll();
                    foreach (var r in roles.Where(r => r.AutoAssign))
                    {
                        RoleManager.AddUser(mu.UserName, r.Id);
                    }
                }

                if (!UserCustomFieldManager.SaveCustomFieldValues((Guid)mu.ProviderUserKey, ctlUserCustomFields.Values))
                {
                    throw new Exception(Resources.Exceptions.SaveCustomFieldValuesError);
                }

                ResetForNewUser();

                resultMsg = GetLocalResourceObject("UserCreated").ToString();
                MessageContainer.IconType = BugNET.UserControls.Message.MessageType.Information;
            }
            catch (Exception ex)
            {
                resultMsg = GetLocalResourceObject("UserCreatedError") + "<br/>" + ex.Message;
                MessageContainer.IconType = BugNET.UserControls.Message.MessageType.Error;
            }

            MessageContainer.Text    = resultMsg;
            MessageContainer.Visible = true;
        }