public Get ( |
||
type | The |
|
createIfNotFound | bool | A |
personAlias | PersonAlias | A |
Результат | EntityType |
public EntityType Get( Type type, bool createIfNotFound, PersonAlias personAlias )
{
var entityType = Get( type.FullName );
if ( entityType != null )
{
return entityType;
}
if ( createIfNotFound )
{
// Create a new context so type can be saved independing of current context
using ( var rockContext = new RockContext() )
{
var EntityTypeService = new EntityTypeService( rockContext );
entityType = new EntityType();
entityType.Name = type.FullName;
entityType.FriendlyName = type.Name.SplitCase();
entityType.AssemblyName = type.AssemblyQualifiedName;
EntityTypeService.Add( entityType );
rockContext.SaveChanges();
}
// Read type using current context
return this.Get( entityType.Id );
}
return null;
}
/// <summary> /// Handles the SaveClick event of the mdEdit 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 mdEdit_SaveClick( object sender, EventArgs e ) { var rockContext = new RockContext(); EntityTypeService entityTypeService = new EntityTypeService( rockContext ); EntityType entityType = entityTypeService.Get( int.Parse( hfEntityTypeId.Value ) ); if ( entityType == null ) { entityType = new EntityType(); entityType.IsEntity = true; entityType.IsSecured = true; entityTypeService.Add( entityType ); } entityType.Name = tbName.Text; entityType.FriendlyName = tbFriendlyName.Text; entityType.IsCommon = cbCommon.Checked; rockContext.SaveChanges(); EntityTypeCache.Flush( entityType.Id ); hfEntityTypeId.Value = string.Empty; HideDialog(); BindGrid(); }