private static Collection <string> SetProfile(HttpContext context, IDictionary <string, object> values) { // return collection of successfully saved settings. Collection <string> failedSettings = new Collection <string>(); if (values == null || values.Count == 0) { // no values were given, so we're done, and there are no failures. return(failedSettings); } ProfileBase profile = context.Profile; Dictionary <string, object> allowedSet = ApplicationServiceHelper.ProfileAllowedSet; // Note that profile may be null, and allowedSet may be null. // Even though no properties will be saved in these cases, we still iterate over the given values to be set, // because we must build up the failed collection anyway. bool profileDirty = false; foreach (KeyValuePair <string, object> entry in values) { string propertyName = entry.Key; if (profile != null && allowedSet != null && allowedSet.ContainsKey(propertyName)) { SettingsProperty settingProperty = ProfileBase.Properties[propertyName]; if (settingProperty != null && !settingProperty.IsReadOnly && (!profile.IsAnonymous || (bool)settingProperty.Attributes["AllowAnonymous"])) { Type propertyType = settingProperty.PropertyType; object convertedValue; if (ObjectConverter.TryConvertObjectToType(entry.Value, propertyType, JavaScriptSerializer, out convertedValue)) { profile[propertyName] = convertedValue; profileDirty = true; // setting successfully saved. // short circuit the foreach so only failed cases fall through. continue; } } } // Failed cases fall through to here. Possible failure reasons: // 1. type couldn't be converted for some reason (TryConvert returns false) // 2. the property doesnt exist (settingProperty == null) // 3. the property is read only (settingProperty.IsReadOnly) // 4. the current user is anonymous and the setting doesn't allow anonymous access // 5. profile for this user is null (profile == null) // 6. no properties are allowed for setting (allowedSet is null) // 7. *this* property is not allowed for setting (allowedSet.Contains returns false) failedSettings.Add(propertyName); } if (profileDirty) { profile.Save(); } return(failedSettings); }
void OnLeave(object o, EventArgs eventArgs) { if (!ProfileManager.Enabled) { return; } if (!app.Context.ProfileInitialized) { return; } if (ProfileManager.AutomaticSaveEnabled) { profile = app.Context.Profile; if (profile == null) { return; } ProfileAutoSaveEventHandler eh = events [profileAutoSavingEvent] as ProfileAutoSaveEventHandler; if (eh != null) { ProfileAutoSaveEventArgs args = new ProfileAutoSaveEventArgs(app.Context); eh(this, args); if (!args.ContinueWithProfileAutoSave) { return; } } profile.Save(); } }
/// <summary> /// this is used to update the user credential info //swaraj on 18 feb 2010 /// </summary> public void update() { try { //update membership information of user objMembershipUser = Membership.GetUser(User.Identity.Name); objMembershipUser.Email = txtEmail.Text; Membership.UpdateUser(objMembershipUser); if (!User.IsInRole("user")) { //update profile information of user objProfileBase = ProfileBase.Create(User.Identity.Name, true); objProfileBase.SetPropertyValue("FName", txtFirstname.Text); objProfileBase.SetPropertyValue("LName", txtLastname.Text); objProfileBase.SetPropertyValue("MobilePhone", txtMobilePhone.Text); objProfileBase.SetPropertyValue("Fax", txtFax.Text); objProfileBase.SetPropertyValue("Address", txtAddress.Text); objProfileBase.SetPropertyValue("ModifiedBy", User.Identity.Name); objProfileBase.SetPropertyValue("PostalCode", txtPostalCode.Text); objProfileBase.SetPropertyValue("State", txtState.Text); objProfileBase.SetPropertyValue("Country", txtCountry.Text); objProfileBase.SetPropertyValue("Fax", txtFax.Text); objProfileBase.SetPropertyValue("WorkPhone", txtWorkPhone.Text); objProfileBase.SetPropertyValue("HomePhone", txtHomePhone.Text); objProfileBase.Save(); } else { UserInfoPrimaryKey objUserInfoPrimaryKey = new UserInfoPrimaryKey(objMembershipUser.ProviderUserKey.ToString()); userInfo = UserInfo.SelectOne(objUserInfoPrimaryKey, ConnectionString); userInfo.UserName = txtUsername.Text; userInfo.FirstName = txtFirstname.Text; userInfo.LastName = txtLastname.Text; userInfo.Address1 = txtAddress.Text; userInfo.WorkPhone = txtWorkPhone.Text; userInfo.CellPhone = txtMobilePhone.Text; userInfo.State = txtState.Text; userInfo.Country = txtCountry.Text; userInfo.PostalCode = txtPostalCode.Text; userInfo.EmailAddress = txtEmail.Text; userInfo.Fax = txtFax.Text; userInfo.HomePhone = txtHomePhone.Text; UserInfos objUserInfos = UserInfo.SelectByField("UserId", objMembershipUser.ProviderUserKey.ToString(), ConnectionString); if (objUserInfos.Count > 0) { userInfo.ListTab = objUserInfos[0].ListTab; userInfo.CampaignTab = objUserInfos[0].CampaignTab; userInfo.AdvancedTab = objUserInfos[0].AdvancedTab; userInfo.ReportsTab = objUserInfos[0].ReportsTab; } userInfo.UpdateUserDetails(); } } catch (Exception ex) { throw ex; } }
protected void Save_Click(object sender, EventArgs e) { objProfileBase = ProfileBase.Create(User.Identity.Name); //insert profile information of user objProfileBase.SetPropertyValue("PriceRate", txtPrice.Text); objProfileBase.SetPropertyValue("Discount", txtDiscount.Text); objProfileBase.SetPropertyValue("Tax", txtTax.Text); objProfileBase.Save(); lblMsg.Style.Add("Color","green"); lblMsg.Text = "Price Rate Settings Updated Successfully."; }
protected void btnUpdate_Click(object sender, EventArgs e) { try { if (Request.QueryString["Username"] != null) { //update existing user //update membership information of user objMembershipUser = Membership.GetUser(User.Identity.Name); objMembershipUser.Email = txtEmail.Text; Membership.UpdateUser(objMembershipUser); objProfileBase = ProfileBase.Create(Request.QueryString["Username"].ToString(), true); //update profile information of user objProfileBase.SetPropertyValue("FName", txtFirstname.Text); objProfileBase.SetPropertyValue("LName", txtLastname.Text); objProfileBase.SetPropertyValue("MobilePhone", txtMobilePhone.Text); objProfileBase.SetPropertyValue("Fax", txtFax.Text); objProfileBase.SetPropertyValue("Address", txtAddress.Text); objProfileBase.SetPropertyValue("ModifiedBy", User.Identity.Name); objProfileBase.Save(); } else { //create a new user //insert membership information of user . MembershipCreateStatus objMembershipCreateStatus; MembershipUser objMembershipUser = Membership.CreateUser(txtUsername.Text, txtPassword.Text, txtEmail.Text, txtSecurityQuestion.Text, txtSecurityAnswer.Text, chkStatus.Checked, out objMembershipCreateStatus); //if user succesfully created than add profile information. if (objMembershipUser != null) { objProfileBase = ProfileBase.Create(txtUsername.Text, true); //insert profile information of user objProfileBase.SetPropertyValue("FName", txtFirstname.Text); objProfileBase.SetPropertyValue("LName", txtLastname.Text); objProfileBase.SetPropertyValue("MobilePhone", txtMobilePhone.Text); objProfileBase.SetPropertyValue("Fax", txtFax.Text); objProfileBase.SetPropertyValue("Address", txtAddress.Text); objProfileBase.SetPropertyValue("ModifiedBy", User.Identity.Name); objProfileBase.Save(); } } } catch (Exception ex) { throw ex; } }
protected void btnCreateClient_Click(object sender, EventArgs e) { try { //create a new user //insert membership information of user . MembershipCreateStatus objMembershipCreateStatus; MembershipUser objMembershipUser = Membership.CreateUser(txtUsername.Text, txtPassword.Text, txtEmail.Text, txtSecurityQuestion.Text, txtSecurityAnswer.Text, chkStatus.Checked, out objMembershipCreateStatus); //Insert role information of user. Roles.AddUserToRole(txtUsername.Text, "client"); //if user succesfully created than add profile information. if (objMembershipUser != null) { objProfileBase = ProfileBase.Create(txtUsername.Text, true); //insert profile information of user objProfileBase.SetPropertyValue("FName", txtFirstname.Text); objProfileBase.SetPropertyValue("LName", txtLastname.Text); objProfileBase.SetPropertyValue("PostalCode", txtPostalCode.Text); objProfileBase.SetPropertyValue("State", txtState.Text); objProfileBase.SetPropertyValue("Country", txtCountry.Text); objProfileBase.SetPropertyValue("HomePhone", txtHomePhone.Text); objProfileBase.SetPropertyValue("WorkPhone", txtWorkPhone.Text); objProfileBase.SetPropertyValue("MobilePhone", txtMobilePhone.Text); objProfileBase.SetPropertyValue("Fax", txtFax.Text); objProfileBase.SetPropertyValue("Address", txtAddress.Text); objProfileBase.SetPropertyValue("CreatedBy", User.Identity.Name); objProfileBase.SetPropertyValue("DBPassword", txtDBPassword.Text); objProfileBase.SetPropertyValue("DBServerName", txtDBServerName.Text); objProfileBase.SetPropertyValue("DBUserID", txtDBUserID.Text); objProfileBase.SetPropertyValue("DBName", txtDBName.Text); objProfileBase.Save(); } divCreateClent.InnerHtml = "Successfully created " + txtUsername.Text + " client"; } catch (Exception ex) { throw ex; } }
private ProfileBase SaveToProfile(Contact contact,ProfileBase profile) { profile.SetPropertyValue("customer_title",contact.Title); profile.SetPropertyValue("customer_first_name", contact.FirstName); profile.SetPropertyValue("customer_last_name",contact.LastName); profile.SetPropertyValue("customer_address_1",contact.Address1); profile.SetPropertyValue("customer_address_2", contact.Address2); profile.SetPropertyValue("customer_address_3", contact.Address3); profile.SetPropertyValue("customer_town",contact.Town); profile.SetPropertyValue("customer_county",contact.County); profile.SetPropertyValue("customer_country", contact.Country); profile.SetPropertyValue("customer_postcode",contact.Postcode); profile.SetPropertyValue("customer_mobile",contact.Mobile); profile.SetPropertyValue("customer_telephone",contact.Telephone); profile.SetPropertyValue("customer_separate_delivery_address", contact.SeparateDeliveryAddress); profile.SetPropertyValue("customer_delivery_address1",contact.DeliveryAddress1); profile.SetPropertyValue("customer_delivery_address2", contact.DeliveryAddress2); profile.SetPropertyValue("customer_delivery_address3", contact.DeliveryAddress3); profile.SetPropertyValue("customer_delivery_town", contact.DeliveryTown); profile.SetPropertyValue("customer_delivery_county", contact.DeliveryCounty); profile.SetPropertyValue("customer_delivery_postcode", contact.DeliveryPostcode); profile.SetPropertyValue("customer_delivery_country",contact.DeliveryCountry); profile.SetPropertyValue("care_contact_number", contact.ExternalContactNumber.ToString()); profile.SetPropertyValue("care_address_number", contact.ExternalAddressNumber.ToString()); profile.Save(); //TODO: what to do with updating email addresses? try { //having to update membership in this convoluted way because of Umbraco bug //see http://umbraco.codeplex.com/workitem/30789 var updateMember = Membership.GetUser(contact.UserName); var m = new umbraco.cms.businesslogic.member.Member((int)updateMember.ProviderUserKey); m.LoginName = contact.Email; m.Email = contact.Email; m.Save(); FormsAuthentication.SetAuthCookie(contact.Email, true); } catch (Exception e) { string err=e.ToString(); } return profile; }
/// <summary> /// RadToolbar OnButtonClick Event for Creating/deleting User /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void RbarBtn_ButtonClick(object sender, Telerik.Web.UI.RadToolBarEventArgs e) { if (e.Item.Text == "Create") { try { lblPopupMsg.Text = string.Empty; MembershipCreateStatus CreateStatus; objClientProfile = ProfileBase.Create(User.Identity.Name.ToString()); objClientMembership = Membership.GetUser(User.Identity.Name.ToString()); string Password = Membership.GeneratePassword(10, 5); Guid uniqueID = Guid.NewGuid(); byte[] bArr = uniqueID.ToByteArray(); int FavouritNo = BitConverter.ToInt32(bArr, 0); ; objMembershipUser = Membership.CreateUser(txtCreateUserName.Text.ToString(), Password.ToString(), txtCreateEmail.Text.ToString(), "Favourite Number", FavouritNo.ToString(), chkUStatus.Checked, out CreateStatus); //checking whether creation succeeded or not switch (CreateStatus.ToString()) { case "Success": Roles.AddUserToRole(txtCreateUserName.Text.ToString(), "user"); objProfileBase = ProfileBase.Create(txtCreateUserName.Text.ToString()); //setting client properties to user objProfileBase.SetPropertyValue("DBName", objClientProfile.GetPropertyValue("DBName")); objProfileBase.SetPropertyValue("DBUserID", objClientProfile.GetPropertyValue("DBUserID")); objProfileBase.SetPropertyValue("DBPassword", objClientProfile.GetPropertyValue("DBPassword")); objProfileBase.SetPropertyValue("DBServerName", objClientProfile.GetPropertyValue("DBServerName")); objProfileBase.SetPropertyValue("ParentUserName", User.Identity.Name); objProfileBase.Save(); //message body StringBuilder body = new StringBuilder(); body.Append("<HTML><BODY>"); body.Append("<table width=\"100%\"><tr><td align=\"left\" colspan=\"3\" style=\"height:4px; color:green;\"><h3></h3> <td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\"> Hi " + txtCreateUserName.Text.ToString() + ",</td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\">Welcome to 1Point</td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\">You can login in to your Account at:</td></tr>"); body.Append("<tr><td colspan=\"3\"><a href=\"" + ConfigurationManager.AppSettings["LoginUrl"] + "\">Login</a></td></tr>"); body.Append("<tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td>User Name : " + txtCreateUserName.Text.ToString() + "</td></tr>"); body.Append("\n<tr><td>Password : " + Password + "</td></tr> <tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\">If there's anything we can do to help, please get in touch.</td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\">Regards,</td></tr>"); body.Append("<tr><td colspan=\"3\">1Point team</td></tr>"); body.Append("<tr><td colspan=\"3\">" + ConfigurationManager.AppSettings["SuperAdminEmail"].ToString().Split(',').GetValue(0) + "</td></tr>"); body.Append("<tr></tr>"); body.Append("<tr><td colspan=\"3\" style=\"color:red;\">This is an automated Email, please don't Reply.</td></tr>"); MailMessage SendMessageToUser = new MailMessage(); SendMessageToUser.To.Add(txtCreateEmail.Text.ToString()); SendMessageToUser.Body = body.ToString(); SendMessageToUser.Subject = "Welcome to 1Point."; SendMessageToUser.IsBodyHtml = true; //To add SuperAdmin email as CC if appsettings contains more than one email seperated by comma SmtpClient SmtpMail = new SmtpClient(); SmtpMail.Send(SendMessageToUser); lblMainMsg.ForeColor = System.Drawing.Color.Green; lblMainMsg.Text = txtCreateUserName.Text + " created successfully"; txtCreateEmail.Text = ""; txtCreateUserName.Text = ""; fillGrid("sort"); UdpanelGrdUsers.Update(); break; case "DuplicateUserName": lblPopupMsg.Text = "Duplicate User Name"; CreateUserModalPopupExtender.Show(); break; case "DuplicateEmail": lblPopupMsg.Text = "Duplicate Email"; CreateUserModalPopupExtender.Show(); break; case "UserRejected": lblPopupMsg.Text = "User Rejected"; CreateUserModalPopupExtender.Show(); break; case "InvalidEmail": case "InvalidUserName": lblPopupMsg.Text = "Please enter valid user name or email"; CreateUserModalPopupExtender.Show(); break; default: lblMainMsg.Text = "Please try with other entries"; break; } } catch (Exception ex) { //throw ex; } } else if (e.Item.Text == "Delete") { DeleteUserModalPopupExtender.Show(); } }
/// <summary> /// This method is used to create user //Developed on 20 feb 2010 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lbtnCreate_Click(object sender, EventArgs e) { try { MembershipCreateStatus CreateStatus; objClientProfile = ProfileBase.Create(User.Identity.Name.ToString()); objClientMembership = Membership.GetUser(User.Identity.Name.ToString()); string Password = Membership.GeneratePassword(10, 5); Guid uniqueID = Guid.NewGuid(); byte[] bArr = uniqueID.ToByteArray(); int FavouritNo = BitConverter.ToInt32(bArr, 0); objMembershipUser = Membership.CreateUser(txtCreateUserName.Text.ToString(), Password.ToString(), txtCreateEmail.Text.ToString(), "Favourite Number", FavouritNo.ToString(), chkUStatus.Checked, out CreateStatus); //checking whether creation succeeded or not switch (CreateStatus.ToString()) { case "Success": Roles.AddUserToRole(txtCreateUserName.Text.ToString(), "user"); objProfileBase = ProfileBase.Create(txtCreateUserName.Text.ToString()); objMembershipUser = Membership.GetUser(txtCreateUserName.Text.ToString().Trim()); userInfo = new UserInfo(ConnectionString); userInfo.UserId = (Guid)objMembershipUser.ProviderUserKey; userInfo.UserName = txtCreateUserName.Text.ToString(); userInfo.FirstName = txtFName.Text.ToString(); userInfo.LastName = txtLName.Text.ToString(); userInfo.Address1 = txtAddress1.Text.ToString(); userInfo.Address2 = txtAddress2.Text.ToString(); userInfo.WorkPhone = txtWPhone.Text.ToString(); userInfo.CellPhone = txtCellPhone.Text.ToString(); userInfo.City = txtCity.Text.ToString(); userInfo.State = txtState.Text.ToString(); userInfo.Country = txtCountry.Text.ToString(); userInfo.PostalCode = txtPCode.Text.ToString(); userInfo.EmailAddress = txtCreateEmail.Text.ToString(); userInfo.ListTab = true; userInfo.CampaignTab = true; userInfo.AdvancedTab = true; userInfo.ReportsTab = true; userInfo.CampaignReportsTab = true; userInfo.Logo = null; bool status = userInfo.Insert(); //Create User in UserPermissions Table insertUserInPermissionsTb(txtCreateUserName.Text.ToString().Trim(), objMembershipUser.ProviderUserKey); if (status) { //setting client properties to user objProfileBase.SetPropertyValue("DBName", objClientProfile.GetPropertyValue("DBName")); objProfileBase.SetPropertyValue("DBUserID", objClientProfile.GetPropertyValue("DBUserID")); objProfileBase.SetPropertyValue("DBPassword", objClientProfile.GetPropertyValue("DBPassword")); objProfileBase.SetPropertyValue("DBServerName", objClientProfile.GetPropertyValue("DBServerName")); objProfileBase.SetPropertyValue("ParentUserName", User.Identity.Name); objProfileBase.Save(); //message body StringBuilder body = new StringBuilder(); body.Append("<HTML><BODY>"); body.Append("<table width=\"100%\"><tr><td align=\"left\" colspan=\"3\" style=\"height:4px; color:green;\"><h3></h3> <td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\"> Hi " + txtCreateUserName.Text.ToString() + ",</td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\">Welcome to 1Point</td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\">You can login in to your Account at:</td></tr>"); body.Append("<tr><td colspan=\"3\"><a href=\"" + ConfigurationManager.AppSettings["LoginUrl"] + "\">Login</a></td></tr>"); body.Append("<tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td>User Name : " + txtCreateUserName.Text.ToString() + "</td></tr>"); body.Append("\n<tr><td>Password : " + Password + "</td></tr> <tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\">If there's anything we can do to help, please get in touch.</td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\">Regards,</td></tr>"); body.Append("<tr><td colspan=\"3\">1Point team</td></tr>"); body.Append("<tr><td colspan=\"3\">" + ConfigurationManager.AppSettings["SuperAdminEmail"].ToString().Split(',').GetValue(0) + "</td></tr>"); body.Append("<tr></tr>"); body.Append("<tr><td colspan=\"3\" style=\"color:red;\">This is an automated Email, please don't Reply.</td></tr>"); MailMessage SendMessageToUser = new MailMessage(); SendMessageToUser.To.Add(txtCreateEmail.Text.ToString()); SendMessageToUser.Body = body.ToString(); SendMessageToUser.Subject = "Welcome to 1Point."; SendMessageToUser.IsBodyHtml = true; //To add SuperAdmin email as CC if appsettings contains more than one email seperated by comma ConfigurationManager.AppSettings["SuperAdminEmail"].ToString().Split(',').ToList().ForEach(delegate(string mail) { SendMessageToUser.CC.Add(mail); }); SmtpClient SmtpMail = new SmtpClient(); SmtpMail.Send(SendMessageToUser); lblMainMsg.ForeColor = System.Drawing.Color.Green; lblMainMsg.Text = "User Account: " + txtCreateUserName.Text + " created successfully"; txtCreateEmail.Text = ""; txtCreateUserName.Text = ""; fillGrid("sort"); UdpanelGrdUsers.Update(); CreateUserModalPopupExtender.Hide(); upCreateUser.Update(); break; } break; case "DuplicateUserName": lblPopupMsg.Text = "Duplicate User Name"; CreateUserModalPopupExtender.Show(); break; case "DuplicateEmail": lblPopupMsg.Text = "Duplicate Email"; CreateUserModalPopupExtender.Show(); break; case "UserRejected": lblPopupMsg.Text = "User Rejected"; CreateUserModalPopupExtender.Show(); break; case "InvalidEmail": case "InvalidUserName": lblPopupMsg.Text = "Please enter valid user name or email"; CreateUserModalPopupExtender.Show(); break; default: lblMainMsg.Text = "Please try with other entries"; break; } } catch (Exception ex) { //throw ex; } }
protected void LbtnEditUpdate_Click(object sender, EventArgs e) { try { //update membership information of user objMembershipUser = Membership.GetUser(txtUsername.Text); objMembershipUser.Email = txtEmail.Text; objMembershipUser.IsApproved = chkStatus.Checked; Membership.UpdateUser(objMembershipUser); objProfileBase = ProfileBase.Create(txtUsername.Text, true); //update profile information of user objProfileBase.SetPropertyValue("FName", txtFirstname.Text); objProfileBase.SetPropertyValue("LName", txtLastname.Text); objProfileBase.SetPropertyValue("MobilePhone", txtMobilePhone.Text); objProfileBase.SetPropertyValue("Fax", txtFax.Text); objProfileBase.SetPropertyValue("Address", txtAddress.Text); objProfileBase.SetPropertyValue("HomePhone", txtHomePhone.Text); objProfileBase.SetPropertyValue("PostalCode", txtPostalCode.Text); objProfileBase.SetPropertyValue("CompanyName", txtCompanyName.Text); objProfileBase.SetPropertyValue("State", txtState.Text); objProfileBase.SetPropertyValue("Country", txtCountry.Text); objProfileBase.SetPropertyValue("WorkPhone", txtWorkPhone.Text); objProfileBase.SetPropertyValue("DBServerName", txtDBServerName.Text); objProfileBase.SetPropertyValue("DBName", txtDBName.Text); objProfileBase.SetPropertyValue("DBUserID", txtDBUserID.Text); objProfileBase.SetPropertyValue("DBPassword", txtDBPassword.Text); objProfileBase.SetPropertyValue("FromDomain", txtFromDomain.Text); objProfileBase.SetPropertyValue("MtaName", txtEVMTAName.Text); objProfileBase.SetPropertyValue("FromName", txtEFromName.Text); objProfileBase.SetPropertyValue("ReplyEmail", txtEReplyEmail.Text); objProfileBase.SetPropertyValue("AccType", ddlEAdminAccType.SelectedItem.Text); objProfileBase.Save(); //developed by swaraj on 26feb 2010 //Used to update the db information of users under a particular client Membership.GetAllUsers().Cast<MembershipUser>().ToList().ForEach(delegate(MembershipUser user) { objProfileBaseUser = ProfileBase.Create(user.UserName, true); if (objProfileBaseUser.GetPropertyValue("ParentUserName").ToString() == objMembershipUser.UserName.ToString()) { objProfileBaseUser.SetPropertyValue("DBServerName", txtDBServerName.Text); objProfileBaseUser.SetPropertyValue("DBName", txtDBName.Text); objProfileBaseUser.SetPropertyValue("DBUserID", txtDBUserID.Text); objProfileBaseUser.SetPropertyValue("DBPassword", txtDBPassword.Text); //to update the status of users if client status is false if (chkStatus.Checked == false) { ObjMembershipUser2 = Membership.GetUser(user.UserName); ObjMembershipUser2.IsApproved = false; Membership.UpdateUser(ObjMembershipUser2); } } objProfileBaseUser.Save(); }); //to update client billing info lblMsg.Style.Add("color", "green"); lblMsg.Text = string.Format("Succesfully updated client {0}.", txtUsername.Text); FillGrid(string.Empty); UpdateClientModalPopupExtender.Hide(); upEditClient.Update(); upClientData.Update(); } catch (Exception ex) { lblMsg.Style.Add("color", "red"); lblMsg.Text = "Error: " + ex.Message; upClientData.Update(); } }
protected void lbtnCreate_Click(object sender, EventArgs e) { try { SqlCommand com = null; SqlConnection conn = null; //create a new user //insert membership information of user . MembershipCreateStatus objMembershipCreateStatus; string Password = Membership.GeneratePassword(10, 5); Guid uniqueID = Guid.NewGuid(); byte[] bArr = uniqueID.ToByteArray(); int FavouritNo = BitConverter.ToInt32(bArr, 0); #region Create database and Restore the DB try { string conString = "Data Source= " + txtCreateDbServerName.Text.ToString() + ";Initial Catalog= master;User ID=" + txtCreateDbUserID.Text.ToString() + ";Password="******"create database " + txtCreateDbName.Text.ToString(), conn); com.CommandType = System.Data.CommandType.Text; int i = com.ExecuteNonQuery(); } //string path = Server.MapPath(@"~\adminpages\ReplyPositive.bak"); string path = ConfigurationManager.AppSettings["RPbackupFile"].ToString(); path = path + "ReplyPositive.bak"; string logPath = ConfigurationManager.AppSettings["sqlMDFLDFPath"].ToString(); string strCommandText; strCommandText = "RESTORE DATABASE " + txtCreateDbName.Text; strCommandText += @" FROM DISK=N'" + path + "'"; strCommandText += @" WITH MOVE 'ReplyPositive' TO '" + logPath + txtCreateDbName.Text + "_Data.mdf',"; strCommandText += @" MOVE 'ReplyPositive_log' TO '" + logPath + txtCreateDbName.Text + "_Log.ldf',"; strCommandText += " FILE = 1,NOUNLOAD,REPLACE,"; strCommandText += " STATS = 25"; com = new SqlCommand(strCommandText, conn); com.CommandType = System.Data.CommandType.Text; int res = com.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { throw new Exception(ex.Message); } #endregion MembershipUser objMembershipUser = Membership.CreateUser(txtCreateUsername.Text, Password.ToString(), txtCreateEmail.Text, "Favourite number", FavouritNo.ToString(), ChkCreateStatus.Checked, out objMembershipCreateStatus); if (objMembershipUser != null) { //Insert role information of user. Roles.AddUserToRole(txtCreateUsername.Text, "client"); objProfileBase = ProfileBase.Create(txtCreateUsername.Text, true); //insert profile information of user objProfileBase.SetPropertyValue("FName", txtCreateFirstName.Text); objProfileBase.SetPropertyValue("LName", txtCreateLastname.Text); objProfileBase.SetPropertyValue("PostalCode", txtCreatePostalCode.Text); objProfileBase.SetPropertyValue("State", txtCreateState.Text); objProfileBase.SetPropertyValue("Country", txtCreateCountry.Text); objProfileBase.SetPropertyValue("CompanyName", txtCreateCompany.Text); objProfileBase.SetPropertyValue("Address", txtCreateAddress.Text); objProfileBase.SetPropertyValue("CreatedBy", User.Identity.Name); objProfileBase.SetPropertyValue("DBPassword", txtCreateDbPassword.Text); objProfileBase.SetPropertyValue("DBServerName", txtCreateDbServerName.Text); objProfileBase.SetPropertyValue("DBUserID", txtCreateDbUserID.Text); objProfileBase.SetPropertyValue("DBName", txtCreateDbName.Text); objProfileBase.SetPropertyValue("FromDomain", txtCreateFromDomain.Text); objProfileBase.SetPropertyValue("HBounce", "1"); objProfileBase.SetPropertyValue("SBounce", "3"); objProfileBase.SetPropertyValue("MtaName", txtVMTAName.Text); objProfileBase.SetPropertyValue("AccType", ddlCAdminAccType.SelectedItem.Text); // Save Client Rec in UserPermissions Table. createClientPermissions(txtCreateUsername.Text, ConnectionString); objProfileBase.Save(); //message body StringBuilder body = new StringBuilder(); body.Append("<HTML><BODY>"); body.Append("<table width=\"100%\"><tr><td align=\"left\" colspan=\"3\" style=\"height:4px; color:green;\"><h3></h3> <td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\"> Hi " + txtCreateUsername.Text.ToString() + ",</td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\">Welcome to 1Point</td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\">You can login in to your accont at:</td></tr>"); body.Append("<tr><td colspan=\"3\"><a href=\"" + ConfigurationManager.AppSettings["LoginUrl"] + "\">Login</a></td></tr>"); body.Append("<tr><td colspan=\"3\"></td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td align=\"right\">User Name : </td><td>" + txtCreateUsername.Text.ToString() + "</td></tr>"); body.Append("\n<tr><td align=\"right\">Pasword : </td><td>" + Password + "</td></tr> <tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\">If there's anything we can do to help, please get in touch.</td></tr><tr><td colspan=\"3\"> </td></tr>"); body.Append("<tr><td colspan=\"3\">Regards,</td></tr>"); body.Append("<tr><td colspan=\"3\">1Point team</td></tr>"); body.Append("<tr><td colspan=\"3\">" + ConfigurationManager.AppSettings["SuperAdminEmail"].ToString().Split(',').GetValue(0) + "</td></tr>"); MailMessage SendMessageToUser = new MailMessage(); SendMessageToUser.To.Add(txtCreateEmail.Text.ToString()); SendMessageToUser.Body = body.ToString(); SendMessageToUser.Subject = "Welcome to 1Point"; SendMessageToUser.IsBodyHtml = true; ConfigurationManager.AppSettings["SuperAdminEmail"].ToString().Split(',').ToList().ForEach( mail => SendMessageToUser.CC.Add(mail)); SmtpClient smtpMail = new SmtpClient(); smtpMail.Send(SendMessageToUser); //To create account for billing section CreateClientInBilling(); lblMsg.Style.Add("color", "green"); lblMsg.Text = string.Format("Client created successfully and password has been sent to {0}", txtCreateEmail.Text); FillGrid(string.Empty); CreateClientPopupExtender.Hide(); upClientData.Update(); } else { lblCreatePopupMsg.Text = objMembershipCreateStatus.ToString(); CreateClientPopupExtender.Show(); } } catch (Exception ex) { //display the message for existed database lblMsg.Style.Add("color", "red"); lblMsg.Text = ex.Message; } }
private void UpdateProfile(ProfileBase profileStorage, IMarket market) { var originalMarketId = profileStorage[_marketIdKey] as string; var currentMarketId = market == null || market.MarketId == MarketId.Default ? string.Empty : market.MarketId.Value; if (!string.Equals(originalMarketId, currentMarketId, StringComparison.Ordinal)) { profileStorage[_marketIdKey] = currentMarketId; profileStorage.Save(); } }
void OnLeave (object o, EventArgs eventArgs) { if (!ProfileManager.Enabled) return; if (!app.Context.ProfileInitialized) return; if (ProfileManager.AutomaticSaveEnabled) { profile = app.Context.Profile; if (profile == null) return; ProfileAutoSaveEventHandler eh = events [profileAutoSavingEvent] as ProfileAutoSaveEventHandler; if (eh != null) { ProfileAutoSaveEventArgs args = new ProfileAutoSaveEventArgs (app.Context); eh (this, args); if (!args.ContinueWithProfileAutoSave) return; } profile.Save (); } }
public ActionResult EditUser(FormCollection form) { string userkey = form["hdnid"].ToString(); MembershipUser edituser = Membership.GetUser(new Guid(userkey)); try { if (userkey != null) { edituser.Email = form["txtemail"].ToString(); if (edituser != null) { var profile = new ProfileBase(); string selectRole = form["ddRoles"].ToString(); bool isInRole = Roles.IsUserInRole(edituser.UserName, selectRole); string[] userCurrentRole = Roles.GetRolesForUser(edituser.UserName); if (!isInRole) { string[] curntrole = Roles.GetAllRoles(); if (curntrole.Length > 0) { foreach (string removeRole in curntrole) { bool isnotinRole = Roles.IsUserInRole(edituser.UserName, removeRole); if (isnotinRole) { Roles.RemoveUserFromRole(edituser.UserName, removeRole); } } } Roles.AddUserToRole(edituser.UserName, selectRole); } profile.Initialize(edituser.UserName, true); profile.SetPropertyValue("FirstName", form["txtfirstname"].ToString()); profile.SetPropertyValue("LastName", form["txtlastname"].ToString()); profile.SetPropertyValue("Phone", form["txtphone"].ToString()); profile.Save(); ViewData["EditUser"] = edituser; Membership.UpdateUser(edituser); ViewData["status"] = "Success"; ViewData["msg"] = "User information updated successfully."; } } } catch (Exception ex) { ViewData["status"] = "Error"; ViewData["msg"] = "Error in User information update."; //return RedirectToAction("AddRole", "Resource"); } ViewData["EditUser"] = edituser; ViewData["RoleList"] = GetAllRoles(); return View("EditUser"); }
public ActionResult EditUser(FormCollection form) { string userkey = form["hdnid"].ToString(); MembershipUser edituser = Membership.GetUser(new Guid(userkey)); try { if (userkey != null) { edituser.Email = form["txtemail"].ToString(); if (edituser != null) { var profile = new ProfileBase(); string selectRole = form["ddRoles"].ToString(); bool isInRole = Roles.IsUserInRole(edituser.UserName, selectRole); string[] userCurrentRole = Roles.GetRolesForUser(edituser.UserName); if (!isInRole) { string[] curntrole = Roles.GetAllRoles(); if (curntrole.Length > 0) { foreach (string removeRole in curntrole) { bool isnotinRole = Roles.IsUserInRole(edituser.UserName, removeRole); if (isnotinRole) { Roles.RemoveUserFromRole(edituser.UserName, removeRole); } } } Roles.AddUserToRole(edituser.UserName, selectRole); } profile.Initialize(edituser.UserName, true); profile.SetPropertyValue("FirstName", form["txtfirstname"].ToString()); profile.SetPropertyValue("LastName", form["txtlastname"].ToString()); profile.SetPropertyValue("Phone", form["txtphone"].ToString()); profile.Save(); PM_MaxUserEfforts userEffort = SynergyService.GetUserEffortById(edituser.UserName); if (form["txteffort"].ToString() == "") { userEffort.MaxEffort = 0; } userEffort.MaxEffort =Convert.ToDecimal(form["txteffort"].ToString()); userEffort.aspnet_Users = SynergyService.GetUserByName(edituser.UserName); SynergyService.UpdateUserEffort(userEffort); List<string> ResourceInfo = new List<string>(); ResourceInfo.Add(form["txtfirstname"].ToString()); //ResourceInfo.Add(form["txtusername"].ToString()); ResourceInfo.Add(form["txtemail"].ToString()); ResourceInfo.Add(form["ddRoles"].ToString()); //ResourceInfo.Add(form["txtfirstname"].ToString()); //ResourceInfo.Add(edituser.UserName); //ResourceInfo.Add(form["txtpwd"].ToString()); //ResourceInfo.Add(form["txtemail"].ToString()); //ResourceInfo.Add(form["ddRoles"].ToString()); SendNotificationWhenAccountUpdated(edituser.Email, ResourceInfo); //SendNotificationWhenAccountUpdated(edituser.Email, ResourceInfo); //ResourceInfo = null; if (!SynergyService.IsEmployeeSystemExternal()) { try { string nic = form["hdnic"].ToString(); EM_Employee employee = SynergyService.GetEmployeebyEmpId(nic); employee.Email = form["txtemail"].ToString(); employee.FirstName = form["txtfirstname"].ToString(); employee.LastName = form["txtlastname"].ToString(); employee.Phone = form["txtphone"].ToString(); string departmentId = form["ddlDepartments"].ToString(); employee.aspnet_Users = SynergyService.GetUserByName(edituser.UserName); employee.EM_Departments = SynergyService.GetDepartmentbyId(Convert.ToInt32(departmentId)); SynergyService.UpdateEmployee(employee); ViewData["DepartmentList"] = GetDepartmentListwithUserSelectedValue(employee.EM_Departments); } catch { } } ViewData["EditUser"] = edituser; Membership.UpdateUser(edituser); ViewData["status"] = "Success"; ViewData["msg"] = "User information updated successfully."; } } } catch (Exception ) { ViewData["status"] = "Error"; ViewData["msg"] = "Error in User information update."; //return RedirectToAction("AddRole", "Resource"); } ViewData["EditUser"] = edituser; //ViewData["RoleList"] = GetAllRoles(); //ViewData["DepartmentList"] = GetDepartmentList(); ViewData["RoleList"] = GetAllRoleswithUserSelectedValue(edituser.UserName); return View("EditUser"); }