/// <summary> /// Handles the Click event of the btnSaveType control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSaveType_Click( object sender, EventArgs e ) { DefinedType definedType = null; DefinedTypeService typeService = new DefinedTypeService(); int definedTypeId = hfDefinedTypeId.ValueAsInt(); if ( definedTypeId == 0 ) { definedType = new DefinedType(); definedType.IsSystem = false; definedType.Order = 0; typeService.Add( definedType, CurrentPersonId ); } else { DefinedTypeCache.Flush( definedTypeId ); definedType = typeService.Get( definedTypeId ); } definedType.Name = tbTypeName.Text; definedType.Category = tbTypeCategory.Text; definedType.Description = tbTypeDescription.Text; definedType.FieldTypeId = int.Parse( ddlTypeFieldType.SelectedValue ); if ( !definedType.IsValid ) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction( () => { typeService.Save( definedType, CurrentPersonId ); // get it back to make sure we have a good Id definedType = typeService.Get( definedType.Guid ); } ); var qryParams = new Dictionary<string, string>(); qryParams["definedTypeId"] = definedType.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
/// <summary> /// Handles the Click event of the btnSaveType control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSaveType_Click( object sender, EventArgs e ) { var rockContext = new RockContext(); DefinedType definedType = null; DefinedTypeService typeService = new DefinedTypeService( rockContext ); int definedTypeId = hfDefinedTypeId.ValueAsInt(); if ( definedTypeId == 0 ) { definedType = new DefinedType(); definedType.IsSystem = false; definedType.Order = 0; typeService.Add( definedType ); } else { DefinedTypeCache.Flush( definedTypeId ); definedType = typeService.Get( definedTypeId ); } definedType.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id; definedType.Name = tbTypeName.Text; definedType.Category = tbTypeCategory.Text; definedType.Description = tbTypeDescription.Text; definedType.HelpText = tbHelpText.Text; if ( !definedType.IsValid ) { // Controls will render the error messages return; } rockContext.SaveChanges(); var qryParams = new Dictionary<string, string>(); qryParams["definedTypeId"] = definedType.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); }
protected void btnSaveType_Click( object sender, EventArgs e ) { using ( new Rock.Data.UnitOfWorkScope() ) { DefinedTypeService typeService = new DefinedTypeService(); DefinedType definedType; int typeId = (( hfIdType.Value ) != null && hfIdType.Value != String.Empty ) ? Int32.Parse( hfIdType.Value ) : 0; if ( typeId == 0 ) { definedType = new DefinedType(); definedType.IsSystem = false; definedType.Order = 0; typeService.Add( definedType, CurrentPersonId ); } else { Rock.Web.Cache.DefinedTypeCache.Flush( typeId ); definedType = typeService.Get( typeId ); } definedType.Name = tbTypeName.Text; definedType.Category = tbTypeCategory.Text; definedType.Description = tbTypeDescription.Text; definedType.FieldTypeId = Int32.Parse( ddlTypeFieldType.SelectedValue ); typeService.Save( definedType, CurrentPersonId ); } rGridType_Bind(); pnlTypeDetails.Visible = false; pnlTypes.Visible = true; }