Esempio n. 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"));
            }
        }
        /// <summary>
        /// Handles the Click event of the lnkAddCustomField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void lnkAddCustomField_Click(object sender, EventArgs e)
        {
            var newName = txtName.Text.Trim();

            if (newName == String.Empty)
            {
                return;
            }

            var dataType  = (ValidationDataType)Enum.Parse(typeof(ValidationDataType), dropDataType.SelectedValue);
            var fieldType = (CustomFieldType)Enum.Parse(typeof(CustomFieldType), rblCustomFieldType.SelectedValue);
            var required  = chkRequired.Checked;

            var newCustomField = new UserCustomField
            {
                Name      = newName,
                DataType  = dataType,
                Required  = required,
                FieldType = fieldType
            };

            if (UserCustomFieldManager.SaveOrUpdate(newCustomField))
            {
                txtName.Text = "";
                dropDataType.SelectedIndex = 0;
                chkRequired.Checked        = false;
                BindCustomFields();
            }
            else
            {
                lblError.Text = LoggingManager.GetErrorMessageResource("SaveCustomFieldError");
            }
        }
Esempio n. 3
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;
        }
        /// <summary>
        /// Binds the custom fields.
        /// </summary>
        private void BindCustomFields()
        {
            //check if we are editing the sub grid - needed to fire update command on the nested grid.
            if (ViewState["EditingSubGrid"] == null)
            {
                grdCustomFields.DataSource   = UserCustomFieldManager.GetAll();
                grdCustomFields.DataKeyField = "Id";
                grdCustomFields.DataBind();

                grdCustomFields.Visible = grdCustomFields.Items.Count != 0;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Handles the Load event of the Page 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 Page_Load(object sender, EventArgs e)
        {
            //need to rebind these on every postback because of dynamic controls
            ctlUserCustomFields.DataSource = UserCustomFieldManager.GetAll();
            ctlUserCustomFields.DataBind();

            if (Page.IsPostBack)
            {
                return;
            }

            ResetForNewUser();
        }
        protected void btnDeleteCustomField_Click(object sender, ImageClickEventArgs e)
        {
            var btn = sender as ImageButton;

            if (btn == null)
            {
                return;
            }

            var id = btn.CommandArgument.To <int>();

            if (!UserCustomFieldManager.Delete(id))
            {
                lblError.Text = LoggingManager.GetErrorMessageResource("DeleteCustomFieldError");
            }
            else
            {
                BindCustomFields();
            }
        }
        /// <summary>
        /// Handles the Update event of the grdCustomFields control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void grdCustomFields_Update(object sender, DataGridCommandEventArgs e)
        {
            var cf = UserCustomFieldManager.GetById(Convert.ToInt32(grdCustomFields.DataKeys[e.Item.ItemIndex]));
            var txtCustomFieldName = (TextBox)e.Item.FindControl("txtCustomFieldName");
            var customFieldType    = (DropDownList)e.Item.FindControl("dropCustomFieldType");
            var dataType           = (DropDownList)e.Item.FindControl("dropEditDataType");
            var required           = (CheckBox)e.Item.FindControl("chkEditRequired");

            cf.Name = txtCustomFieldName.Text;

            var DataType  = (ValidationDataType)Enum.Parse(typeof(ValidationDataType), dataType.SelectedValue);
            var FieldType = (CustomFieldType)Enum.Parse(typeof(CustomFieldType), customFieldType.SelectedValue);

            cf.FieldType = FieldType;
            cf.DataType  = DataType;
            cf.Required  = required.Checked;
            UserCustomFieldManager.SaveOrUpdate(cf);

            grdCustomFields.EditItemIndex = -1;
            BindCustomFields();
        }
Esempio n. 8
0
 /// <summary>
 /// Handles the Load event of the Page 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 Page_Load(object sender, EventArgs e)
 {
     ctlUserCustomFields.DataSource = UserCustomFieldManager.GetByUserId(UserId);
     ctlUserCustomFields.DataBind();
 }