protected void btnAddAttribute_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbAttrName.Text)) { lbErrorText.Text = (string)GetLocalResourceObject("noAttrNameData"); lbErrorText.Visible = true; return; } PersonAttributeType attr = new PersonAttributeType(); if (UserAttributeId > 0) { attr.Load(UserAttributeId); UserAttributeId = -1; } else { if (PersonAttributeType.GetAttributeType(tbAttrName.Text) != null) { lbErrorText.Text = (string) GetLocalResourceObject("isAttrError"); lbErrorText.Visible = true; return; } } attr.AttributeName = tbAttrName.Text; attr.ShowToUsers = cbShowToUsers.Checked; attr.Save(); clearData(); }
/// <summary> /// Adds standard string attribute. /// </summary> /// <param name="typeName">Type name of attribute.</param> /// <param name="value">Value of attribute.</param> /// <returns>Created attribute.</returns> public PersonAttribute AddStandardStringAttribute(string typeName, string value) { if (ID == null || string.IsNullOrEmpty(value)) return null; try { PersonAttributeType type = PersonAttributeType.GetAttributeType(typeName); if (type == null) { type = new PersonAttributeType() { AttributeName = typeName, ShowToUsers = false }; type.Save(); } return AddStandardStringAttribute(type, value); } catch (Exception ex) { Logger.Log.Error(ex.Message, ex); return null; } }