本文整理汇总了C#中UserInfo.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# UserInfo.SetValue方法的具体用法?C# UserInfo.SetValue怎么用?C# UserInfo.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserInfo
的用法示例。
在下文中一共展示了UserInfo.SetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnOK_Click
/// <summary>
/// Sets data to database.
/// </summary>
protected void btnOK_Click(object sender, EventArgs e)
{
if (!ECommerceContext.IsUserAuthorizedToModifyCustomer())
{
RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
}
string errorMessage = "";
if ((txtCustomerCompany.Text == null || txtCustomerCompany.Text.Trim() == "") &&
((txtCustomerFirstName.Text == null || txtCustomerFirstName.Text.Trim() == "") ||
(txtCustomerLastName.Text == null || txtCustomerLastName.Text.Trim() == "")))
{
errorMessage = GetString("Customers_Edit.errorInsert");
}
if (errorMessage == "")
{
if (this.chkCreateLogin.Checked)
{
errorMessage = new Validator().NotEmpty(txtUserName.Text.Trim(), GetString("Customer_Edit_Login_Edit.rqvUserName"))
.NotEmpty(passStrength.Text.Trim(), GetString("Customer_Edit_Login_Edit.rqvPassword1"))
.NotEmpty(txtPassword2.Text.Trim(), GetString("Customer_Edit_Login_Edit.rqvPassword2")).Result;
// Check policy
if ((errorMessage == "") && !passStrength.IsValid())
{
errorMessage = UserInfoProvider.GetPolicyViolationMessage(CMSContext.CurrentSiteName);
}
// Compare passwords
if ((errorMessage == "") && (passStrength.Text != txtPassword2.Text))
{
errorMessage = GetString("Customer_Edit_Login_Edit.DifferentPasswords");
}
}
}
if (errorMessage == "")
{
if (this.chkCreateLogin.Checked)
{
// If user already has the record in the CMS_User table
UserInfo existingUser = UserInfoProvider.GetUserInfo(txtUserName.Text.Trim());
if (existingUser != null)
{
errorMessage = GetString("Customer_Edit_Login_Edit.UserExist");
}
}
}
if (errorMessage == "")
{
CustomerInfo customerObj = CustomerInfoProvider.GetCustomerInfo(customerid);
// If customer doesn't already exist, create new one
if (customerObj == null)
{
customerObj = new CustomerInfo();
customerObj.CustomerSiteID = CMSContext.CurrentSiteID;
}
customerObj.CustomerLastName = txtCustomerLastName.Text.Trim();
customerObj.CustomerFirstName = txtCustomerFirstName.Text.Trim();
customerObj.CustomerCompany = txtCustomerCompany.Text.Trim();
customerObj.CustomerCountryID = drpCountry.CountryID;
customerObj.CustomerStateID = drpCountry.StateID;
customerObj.CustomerEnabled = true;
//customerObj.CustomerCreated = ucCustomerCreated.SelectedDateTime;
using (CMSTransactionScope tr = new CMSTransactionScope())
{
CustomerInfoProvider.SetCustomerInfo(customerObj);
// If create login checked
if (this.chkCreateLogin.Checked)
{
UserInfo ui = new UserInfo();
ui.UserName = txtUserName.Text.Trim();
ui.FullName = customerObj.CustomerFirstName + " " + customerObj.CustomerLastName;
ui.IsGlobalAdministrator = false;
ui.SetValue("UserEnabled", true);
UserInfoProvider.SetPassword(ui, passStrength.Text);
// Add user to current site
UserInfoProvider.AddUserToSite(ui.UserName, CMSContext.CurrentSiteName);
customerObj.CustomerUserID = ui.UserID;
CustomerInfoProvider.SetCustomerInfo(customerObj);
}
// Commit transaction
tr.Commit();
}
URLHelper.Redirect("Customer_Edit_Frameset.aspx?customerid=" + Convert.ToString(customerObj.CustomerID) + "&saved=1");
//.........这里部分代码省略.........
示例2: Save
/// <summary>
/// Saves customer data and returns customer ID.
/// </summary>
public int Save()
{
if (!IsValid())
{
return 0;
}
// Create customer
CustomerInfo customer = new CustomerInfo()
{
CustomerSiteID = CMSContext.CurrentSiteID,
CustomerFirstName = txtCustomerFirstName.Text.Trim().Truncate(100),
CustomerLastName = txtCustomerLastName.Text.Trim().Truncate(100),
CustomerCompany = txtCustomerCompany.Text.Trim(),
CustomerOrganizationID = txtOrganizationID.Text.Trim(),
CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(),
CustomerCountryID = drpCountry.CountryID,
CustomerStateID = drpCountry.StateID,
CustomerEmail = txtCustomerEmail.Text.Trim().Truncate(100),
CustomerPhone = txtCustomerPhone.Text.Trim(),
CustomerFax = txtCustomerFax.Text.Trim(),
CustomerEnabled = true
};
// Save data in transaction
using (CMSTransactionScope tr = new CMSTransactionScope())
{
CustomerInfoProvider.SetCustomerInfo(customer);
if (chkCreateLogin.Checked)
{
// Create user
UserInfo user = new UserInfo()
{
UserName = txtUserName.Text.Trim(),
FullName = customer.CustomerFirstName + " " + customer.CustomerLastName,
IsGlobalAdministrator = false
};
user.SetValue("UserEnabled", true);
UserInfoProvider.SetPassword(user, passStrength.Text);
UserInfoProvider.AddUserToSite(user.UserName, CMSContext.CurrentSiteName);
customer.CustomerUserID = user.UserID;
CustomerInfoProvider.SetCustomerInfo(customer);
}
tr.Commit();
}
return customer.CustomerID;
}