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="T:System.EventArgs"/> instance containing the event data.</param>
        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                // Guid UserGuid = new System.Guid(User);
                // MembershipUser objUser = UserIT.GetUser(UserGuid);

                // Need to use the MembershipUser and profile classes directly here because
                // we may need to convert between AgentUser, ContractUserEntity,
                // User.  The easiest way to do that is to deal directly with those classes
                // Then call Users.GetUser to get the new type of User.
                MembershipUser objUser = Membership.GetUser(User);
                if (objUser != null)
                {
                    WebProfile prof = WebProfile.GetProfile(User);
                    if (prof == null) prof = new WebProfile();

                    objUser.IsApproved = Active.Checked;
                    objUser.UnlockUser();
                    objUser.Email = Email.Text;
                    if (rbAgent.Checked)
                    {
                        prof.AgentId = int.Parse(ddlSelector.SelectedValue);
                        prof.ContactId = 0;
                    }
                    else if (rbCustomer.Checked)
                    {
                        prof.AgentId = 0;
                        prof.ContactId = int.Parse(ddlSelector.SelectedValue);
                    }
                    else
                    {
                        prof.AgentId = 0;
                        prof.ContactId = 0;
                    }
                    Membership.UpdateUser(objUser);
                    prof.Save();

                    Server.Transfer(_CancelNavigateUrl, false);
                }
            }
            catch (Exception ex)
            {
                //TODO:log this error, display a friendly error message
                ErrorMessage.Message = ex.Message;
            }
        }
Example #2
0
        public static void Update(User user)
        {
            MembershipUser aspUser = Membership.GetUser(user.Username);
            if (aspUser == null) return;
            WebProfile profile = WebProfile.GetProfile(user.Username);
            if (profile == null)
            {
                profile = new WebProfile();
            }

            if (user is AgentUser)
            {
                AgentUser agent = (AgentUser)user;
                profile.AgentId = agent.AgentId;
            }
            else
            {
                profile.AgentId = 0;
            }

            if (user is ContactUser)
            {
                ContactUser contact = (ContactUser)user;
                profile.ContactId = contact.ContactId;
            }
            else
            {
                profile.ContactId = 0;
            }

            aspUser.IsApproved = user.IsActive;
            if (user.IsActive)
            {
                aspUser.UnlockUser();
            }

            profile.Save();
            Membership.UpdateUser(aspUser);
        }