Beispiel #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                UserProfile    userProfile = new UserProfile();
                MembershipUser user;
                string         password = Membership.GeneratePassword(8, 1);
                if (!string.IsNullOrEmpty(Request.Params["Id"]))
                {
                    userProfile = DALHelper.GetUsers(userCriteria => userCriteria.UserId == new Guid(Request.Params["id"])).First();
                    user        = Membership.GetUser(this.txtEmail.Text);
                }
                else
                {
                    if (Membership.GetUser(this.txtEmail.Text) != null)
                    {
                        this.ltrlMessage.Text = UICommon.GetErrorMessage("User already exists");
                        //System.Windows.Forms.MessageBox.Show("User already exists", "Add Edit User");
                        return;
                    }

                    //string password = "******";
                    user = Membership.CreateUser(this.txtEmail.Text, password);

                    userProfile.CreatedDate = DateTime.Now;
                    userProfile.CreatedBy   = UICommon.GetCurrentUserID();
                }

                user.IsApproved = this.chkActive.Checked;
                Membership.UpdateUser(user);
                userProfile.ModifiedDate = DateTime.Now;
                userProfile.ModifiedBy   = UICommon.GetCurrentUserID();
                userProfile.UserId       = new Guid(user.ProviderUserKey.ToString());
                userProfile.FirstName    = this.txtFirstName.Text;
                userProfile.LastName     = this.txtLastName.Text;
                userProfile.Email        = this.txtEmail.Text;
                userProfile.ContacInfo   = this.txtContactInfo.Text;
                userProfile.CreatedDate  = DateTime.Now;
                userProfile.Active       = this.chkActive.Checked;
                userProfile.UserName     = user.UserName;
                DALHelper.UpdateUserProfile(userProfile);

                DataTable dtLogin = ObjclsFrms.loadList("SelLoginCredentailsForNAC", "sp_Masters");
                if (dtLogin.Rows.Count > 0)
                {
                    MailService(dtLogin, "BSMEA - Eclaim Account Activation for BSMEA Users", password);
                }
            }
            catch (Exception ex)
            {
                UICommon.LogException(ex, "Add Edit User");
                String innerMessage = (ex.InnerException != null) ? ex.InnerException.Message : "";
                ObjclsFrms.LogMessageToFile(UICommon.GetLogFileName(), "AddEditUser.aspx btnSave_Click()", "Error : " + ex.Message.ToString() + " - " + innerMessage);
            }
            Response.Redirect("Users.aspx");
        }