public DefinedTypeSummary( DefinedType dt ) { if ( dt != null ) { Id = dt.Id.ToString(); //Category = dt.Category; Name = dt.Name; Description = dt.Description; UniqueIdentifier = dt.Guid; ForeignId = dt.ForeignId; IsSystem = dt.IsSystem; FieldTypeId = dt.FieldTypeId; HelpText = dt.HelpText; if(dt.DefinedValues != null && dt.DefinedValues.Count > 0) { ValueSummaries = dt.DefinedValues.Select( dv => new DefinedValueSummary() { Id = dv.Id.ToString(), DefinedTypeId = dv.DefinedTypeId.ToString(), Value = dv.Value, Description = dv.Description, ForeignId = dv.ForeignId, Order = dv.Order, IsSystem = dv.IsSystem } ).ToList(); } } }
/// <summary> /// Handles the Click event of the btnDelete 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 btnDelete_Click(object sender, EventArgs e) { RockContext rockContext = new RockContext(); DefinedTypeService definedTypeService = new DefinedTypeService(rockContext); DefinedType definedType = definedTypeService.Get(int.Parse(hfDefinedTypeId.Value)); if (definedType != null) { if (!definedType.IsAuthorized(Authorization.EDIT, this.CurrentPerson)) { mdDeleteWarning.Show("Sorry, You are not authorized to delete this Defined Type.", ModalAlertType.Information); return; } string errorMessage; if (!definedTypeService.CanDelete(definedType, out errorMessage)) { mdDeleteWarning.Show(errorMessage, ModalAlertType.Information); return; } definedTypeService.Delete(definedType); rockContext.SaveChanges(); } NavigateToParentPage(); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> public void ShowDetail(string itemKey, int itemKeyValue) { if (!itemKey.Equals("definedTypeId")) { return; } pnlDetails.Visible = true; DefinedType definedType = null; if (!itemKeyValue.Equals(0)) { definedType = new DefinedTypeService().Get(itemKeyValue); } else { definedType = new DefinedType { Id = 0 }; } hfDefinedTypeId.SetValue(definedType.Id); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if (!IsUserAuthorized("Edit")) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(DefinedType.FriendlyTypeName); } if (definedType.IsSystem) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(DefinedType.FriendlyTypeName); } if (readOnly) { btnEdit.Visible = false; ShowReadonlyDetails(definedType); } else { btnEdit.Visible = true; if (definedType.Id > 0) { ShowReadonlyDetails(definedType); } else { ShowEditDetails(definedType); } } BindDefinedTypeAttributesGrid(); BindDefinedValuesGrid(); }
/// <summary> /// Shows the readonly details. /// </summary> /// <param name="definedType">Type of the defined.</param> private void ShowReadonlyDetails(DefinedType definedType) { SetEditMode(false); hfDefinedTypeId.SetValue(definedType.Id); tbTypeName.Text = definedType.Name; lTitle.Text = definedType.Name.FormatAsHtmlTitle(); lDescription.Text = definedType.Description.ConvertMarkdownToHtml(); if (!string.IsNullOrWhiteSpace(definedType.HelpText)) { lHelpText.Text = definedType.HelpText; rcHelpText.Visible = true; } else { rcHelpText.Visible = false; } definedType.LoadAttributes(); if (!_isStandAlone && definedType.Category != null) { lblMainDetails.Text = new DescriptionList() .Add("Category", definedType.Category.Name) .Html; } }
protected DefinedType GetMappedDefinedType(DefinedType source) { var tModel = _match.Target.SchemaModel == source.SchemaModel ? _match.Source.SchemaModel : _match.Target.SchemaModel; if (source.Name == "IfcSoundPowerLevelMeasure") { return(tModel.Get <DefinedType>( t => string.Compare("IfcSoundPowerMeasure", t.Name, StringComparison.InvariantCultureIgnoreCase) == 0) .FirstOrDefault()); } if (source.Name == "IfcSoundPressureLevelMeasure") { return(tModel.Get <DefinedType>( t => string.Compare("IfcSoundPressureMeasure", t.Name, StringComparison.InvariantCultureIgnoreCase) == 0) .FirstOrDefault()); } var nameMatch = tModel.Get <DefinedType>( t => string.Compare(source.Name, t.Name, StringComparison.InvariantCultureIgnoreCase) == 0) .FirstOrDefault(); return(nameMatch); }
/// <summary> /// Handles the Click event of the btnEdit 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 btnEdit_Click(object sender, EventArgs e) { DefinedTypeService definedTypeService = new DefinedTypeService(new RockContext()); DefinedType definedType = definedTypeService.Get(hfDefinedTypeId.ValueAsInt()); ShowEditDetails(definedType); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit( EventArgs e ) { base.OnInit( e ); // this event gets fired after block settings are updated. it's nice to repaint the screen if these settings would alter it this.BlockUpdated += Block_BlockUpdated; this.AddConfigurationUpdateTrigger( upnlSettings ); int definedTypeId = InitForDefinedType(); _definedType = new DefinedTypeService( new RockContext() ).Get( definedTypeId ); if ( _definedType != null ) { gDefinedValues.DataKeyNames = new string[] { "id" }; gDefinedValues.Actions.ShowAdd = true; gDefinedValues.Actions.AddClick += gDefinedValues_Add; gDefinedValues.GridRebind += gDefinedValues_GridRebind; gDefinedValues.GridReorder += gDefinedValues_GridReorder; bool canAddEditDelete = IsUserAuthorized( Authorization.EDIT ); gDefinedValues.Actions.ShowAdd = canAddEditDelete; gDefinedValues.IsDeleteEnabled = canAddEditDelete; AddAttributeColumns(); var deleteField = new DeleteField(); gDefinedValues.Columns.Add( deleteField ); deleteField.Click += gDefinedValues_Delete; modalValue.SaveClick += btnSaveValue_Click; modalValue.OnCancelScript = string.Format( "$('#{0}').val('');", hfDefinedValueId.ClientID ); } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); // this event gets fired after block settings are updated. it's nice to repaint the screen if these settings would alter it this.BlockUpdated += Block_BlockUpdated; this.AddConfigurationUpdateTrigger(upnlSettings); int definedTypeId = InitForDefinedType(); _definedType = new DefinedTypeService(new RockContext()).Get(definedTypeId); if (_definedType != null) { gDefinedValues.DataKeyNames = new string[] { "Id" }; gDefinedValues.Actions.ShowAdd = true; gDefinedValues.Actions.AddClick += gDefinedValues_Add; gDefinedValues.GridRebind += gDefinedValues_GridRebind; gDefinedValues.GridReorder += gDefinedValues_GridReorder; bool canAddEditDelete = IsUserAuthorized(Authorization.EDIT); gDefinedValues.Actions.ShowAdd = canAddEditDelete; gDefinedValues.IsDeleteEnabled = canAddEditDelete; AddAttributeColumns(); var deleteField = new DeleteField(); gDefinedValues.Columns.Add(deleteField); deleteField.Click += gDefinedValues_Delete; modalValue.SaveClick += btnSaveValue_Click; modalValue.OnCancelScript = string.Format("$('#{0}').val('');", hfDefinedValueId.ClientID); } }
public DefinedTypeSummary LoadDefinedTypeSummary( DefinedType dt ) { DefinedValueController definedValueController = new DefinedValueController( Service ); dt.DefinedValues = definedValueController.GetByDefinedTypeId( dt.Id ); return new DefinedTypeSummary( dt ); }
/// <summary> /// Adiciona un nuevo tipo a la clase codigo /// </summary> /// <param name="typeCodeName"></param> /// <param name="type"></param> public void AddTypeBuilder(string typeCodeName, Type type) { if (DefinedType.ContainsKey(typeCodeName)) { throw new ArgumentException("Un tipo con ese nombre ya fue declarado en el codigo"); } DefinedType.Add(typeCodeName, type); }
private static void PopulateDefinedValues() { _transactionValue = _definedValueService.GetByGuid(CONTRIBUTION_TYPE_GUID.AsGuid()); _checkValue = _definedValueService.GetByGuid(CHECK_GUID.AsGuid()); _cashValue = _definedValueService.GetByGuid(CASH_GUID.AsGuid()); _creditCardValue = _definedValueService.GetByGuid(CREDIT_CARD_GUID.AsGuid()); _visaValue = _definedValueService.GetByGuid(VISA_CARD_GUID.AsGuid()); _sourceType = _definedTypeService.GetByGuid(SOURCE_TYPE_GUID.AsGuid()); }
/// <summary> /// Devuelve un tipo dado su nombre. Si el tipo no esta definido se crea solamente con el nombre /// </summary> /// <param name="typeCodeName"></param> /// <returns></returns> public Type GetTypeBuilderMaybeNotCreated(string typeCodeName) { if (DefinedType.ContainsKey(typeCodeName)) { return(DefinedType[typeCodeName]); } DefinedType.Add(typeCodeName, Module.DefineType(typeCodeName)); return(DefinedType[typeCodeName]); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); // this event gets fired after block settings are updated. it's nice to repaint the screen if these settings would alter it this.BlockUpdated += Block_BlockUpdated; this.AddConfigurationUpdateTrigger(upnlSettings); int definedTypeId = InitForDefinedType(); _definedType = new DefinedTypeService(new RockContext()).Get(definedTypeId); if (_definedType != null) { gDefinedValues.DataKeyNames = new string[] { "Id" }; gDefinedValues.Actions.ShowAdd = true; gDefinedValues.Actions.AddClick += gDefinedValues_Add; gDefinedValues.GridRebind += gDefinedValues_GridRebind; gDefinedValues.GridReorder += gDefinedValues_GridReorder; bool canAddEditDelete = IsUserAuthorized(Authorization.EDIT); gDefinedValues.Actions.ShowAdd = canAddEditDelete; gDefinedValues.IsDeleteEnabled = canAddEditDelete; AddAttributeColumns(); if (_definedType.EnableSecurityOnValues) { var securityField = new SecurityField(); securityField.ButtonCssClass = "btn btn-security btn-xs"; securityField.ToolTip = "Secure Defined Value"; securityField.EntityTypeId = EntityTypeCache.GetId(Rock.SystemGuid.EntityType.DEFINED_VALUE).Value; gDefinedValues.Columns.Add(securityField); } var deleteField = new DeleteField(); gDefinedValues.Columns.Add(deleteField); deleteField.Click += gDefinedValues_Delete; modalValue.SaveClick += btnSaveValue_Click; modalValue.OnCancelScript = string.Format("$('#{0}').val('');", hfDefinedValueId.ClientID); lTitle.Text = _definedType.Name; } else { lTitle.Text = "Values"; } }
/// <summary> /// Handles the Click event of the btnCancelType 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 btnCancelType_Click(object sender, EventArgs e) { if (hfDefinedTypeId.IsZero()) { // Cancelling on Add. Return to Grid NavigateToParentPage(); } else { // Cancelling on Edit. Return to Details DefinedTypeService definedTypeService = new DefinedTypeService(new RockContext()); DefinedType definedType = definedTypeService.Get(hfDefinedTypeId.ValueAsInt()); ShowReadonlyDetails(definedType); } }
/// <summary> /// Shows the edit details. /// </summary> /// <param name="definedType">Type of the defined.</param> private void ShowEditDetails(DefinedType definedType) { if (definedType.Id > 0) { lActionTitle.Text = ActionTitle.Edit(DefinedType.FriendlyTypeName); } else { lActionTitle.Text = ActionTitle.Add(DefinedType.FriendlyTypeName); } SetEditMode(true); tbTypeName.Text = definedType.Name; tbTypeCategory.Text = definedType.Category; tbTypeDescription.Text = definedType.Description; ddlTypeFieldType.SetValue(definedType.FieldTypeId); }
/// <summary> /// Shows the edit details. /// </summary> /// <param name="definedType">Type of the defined.</param> private void ShowEditDetails(DefinedType definedType) { if (definedType.Id > 0) { lTitle.Text = ActionTitle.Edit(DefinedType.FriendlyTypeName).FormatAsHtmlTitle(); } else { lTitle.Text = ActionTitle.Add(DefinedType.FriendlyTypeName).FormatAsHtmlTitle(); } SetEditMode(true); tbTypeName.Text = definedType.Name; cpCategory.SetValue(definedType.CategoryId); tbTypeDescription.Text = definedType.Description; tbHelpText.Text = definedType.HelpText; }
/// <summary> /// Shows the readonly details. /// </summary> /// <param name="definedType">Type of the defined.</param> private void ShowReadonlyDetails(DefinedType definedType) { SetEditMode(false); hfDefinedTypeId.SetValue(definedType.Id); tbTypeName.Text = definedType.Name; definedType.FieldType = definedType.FieldType ?? new FieldTypeService().Get(definedType.FieldTypeId ?? 0); lblMainDetails.Text = new DescriptionList() .Add("Name", definedType.Name) .Add("Description", definedType.Description) .Add("Category", definedType.Category) .Add("FieldType", definedType.FieldType.Name) .Html; definedType.LoadAttributes(); }
/// <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(this.CurrentPage.Guid, qryParams); }
/// <summary> /// Handles the Delete event of the gDefinedType control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gDefinedType_Delete(object sender, RowEventArgs e) { var definedValueService = new DefinedValueService(); var definedTypeService = new DefinedTypeService(); DefinedType type = definedTypeService.Get(e.RowKeyId); if (type != null) { string errorMessage; if (!definedTypeService.CanDelete(type, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } // if this DefinedType has DefinedValues, see if they can be deleted var definedValues = definedValueService.GetByDefinedTypeId(type.Id).ToList(); foreach (var value in definedValues) { if (!definedValueService.CanDelete(value, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } } RockTransactionScope.WrapTransaction(() => { foreach (var value in definedValues) { definedValueService.Delete(value, CurrentPersonId); definedValueService.Save(value, CurrentPersonId); } definedTypeService.Delete(type, CurrentPersonId); definedTypeService.Save(type, CurrentPersonId); }); } gDefinedType_Bind(); }
/// <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.CategoryId = cpCategory.SelectedValueAsInt(); 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); }
/// <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 { Rock.Web.Cache.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); }); ShowReadonlyDetails(definedType); }
/// <summary> /// Handles the Delete event of the gDefinedType control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gDefinedType_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); var definedValueService = new DefinedValueService(rockContext); var definedTypeService = new DefinedTypeService(rockContext); DefinedType type = definedTypeService.Get(e.RowKeyId); if (type != null) { string errorMessage; if (!definedTypeService.CanDelete(type, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } // if this DefinedType has DefinedValues, see if they can be deleted var definedValues = definedValueService.GetByDefinedTypeId(type.Id).ToList(); foreach (var value in definedValues) { if (!definedValueService.CanDelete(value, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } } foreach (var value in definedValues) { definedValueService.Delete(value); } definedTypeService.Delete(type); rockContext.SaveChanges(); } gDefinedType_Bind(); }
/// <summary> /// Asocia una funcion con el wrapper que ella crea. /// </summary> /// <param name="functionCodeName"></param> /// <param name="typeWrapperCodeName"></param> public void AsociatteMethodToWrapper(string functionCodeName, string typeWrapperCodeName) { if (!DefinedMethod.ContainsKey(functionCodeName)) { throw new ArgumentException("La funcion debe ser annadida antes"); } if (!DefinedType.ContainsKey(typeWrapperCodeName)) { throw new ArgumentException("El tipo tiene que ser annadido antes"); } if (FuntionWrapper.ContainsKey(functionCodeName)) { throw new ArgumentException("Ya se ha asociado esa funcion a ese tipo"); } var typeBuilder = (TypeBuilder)DefinedType[typeWrapperCodeName]; var typeCodeInfo = new TypeCodeInfo { TypeCodeName = typeWrapperCodeName, Type = typeBuilder }; FuntionWrapper.Add(functionCodeName, typeCodeInfo); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> public void ShowDetail(string itemKey, int itemKeyValue) { if (!itemKey.Equals("definedTypeId")) { return; } pnlList.Visible = true; DefinedType definedType = null; if (!itemKeyValue.Equals(0)) { definedType = new DefinedTypeService().Get(itemKeyValue); } else { definedType = new DefinedType { Id = 0 }; } hfDefinedTypeId.SetValue(definedType.Id); BindDefinedValuesGrid(); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); // this event gets fired after block settings are updated. it's nice to repaint the screen if these settings would alter it this.BlockUpdated += Block_BlockUpdated; this.AddConfigurationUpdateTrigger(upnlSettings); int definedTypeId = InitForDefinedType(); _definedType = new DefinedTypeService(new RockContext()).Get(definedTypeId); if (_definedType != null) { gfDefinedValues.ApplyFilterClick += gfDefinedValues_ApplyFilterClick; gfDefinedValues.DisplayFilterValue += gfDefinedValues_DisplayFilterValue; gDefinedValues.DataKeyNames = new string[] { "Id" }; gDefinedValues.Actions.ShowAdd = true; gDefinedValues.Actions.AddClick += gDefinedValues_Add; gDefinedValues.GridRebind += gDefinedValues_GridRebind; _canEdit = IsUserAuthorized(Authorization.EDIT); gDefinedValues.Actions.ShowAdd = _canEdit; gDefinedValues.IsDeleteEnabled = _canEdit; modalValue.SaveClick += btnSaveValue_Click; modalValue.OnCancelScript = string.Format("$('#{0}').val('');", hfDefinedValueId.ClientID); lTitle.Text = _definedType.Name; } else { lTitle.Text = "Values"; } }
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; }
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; }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> public void ShowDetail( string itemKey, int itemKeyValue ) { if ( !itemKey.Equals( "definedTypeId" ) ) { return; } pnlDetails.Visible = true; DefinedType definedType = null; if ( !itemKeyValue.Equals( 0 ) ) { definedType = new DefinedTypeService( new RockContext() ).Get( itemKeyValue ); // If bad data was passed in, return and show nothing. if ( definedType == null ) { pnlDetails.Visible = false; return; } } else { definedType = new DefinedType { Id = 0 }; } hfDefinedTypeId.SetValue( definedType.Id ); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if ( _isReadOnly || !IsUserAuthorized( Authorization.EDIT ) ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( DefinedType.FriendlyTypeName ); } if ( definedType.IsSystem ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( DefinedType.FriendlyTypeName ); } if ( readOnly ) { btnEdit.Visible = false; ShowReadonlyDetails( definedType ); } else { btnEdit.Visible = true; if ( definedType.Id > 0 ) { ShowReadonlyDetails( definedType ); } else { ShowEditDetails( definedType ); } } BindDefinedTypeAttributesGrid(); }
/// <summary> /// Shows the readonly details. /// </summary> /// <param name="definedType">Type of the defined.</param> private void ShowReadonlyDetails( DefinedType definedType ) { SetEditMode( false ); hfDefinedTypeId.SetValue( definedType.Id ); tbTypeName.Text = definedType.Name; lTitle.Text = definedType.Name.FormatAsHtmlTitle(); lDescription.Text = definedType.Description; if ( !string.IsNullOrWhiteSpace( definedType.HelpText ) ) { lHelpText.Text = definedType.HelpText; rcHelpText.Visible = true; } else { rcHelpText.Visible = false; } lblMainDetails.Text = new DescriptionList() .Add("Category", definedType.Category) .Html; definedType.LoadAttributes(); }
protected string GetBaseSystemType(DefinedType type) { return(TypeHelper.GetCSType(type.Domain, Settings)); }
/// <summary> /// Maps the Giftedness Program. /// </summary> /// <param name="tableData">The table data.</param> private void MapGiftednessProgram(IQueryable <Row> tableData) { int completed = 0; int totalRows = tableData.Count(); int percentage = (totalRows - 1) / 100 + 1; ReportProgress(0, string.Format("Verifying Giftedness Program import ({0:N0} found).", totalRows)); foreach (var row in tableData) { var rockContext = new RockContext(); var categoryList = new CategoryService(rockContext).Queryable().ToList(); var attributeList = new AttributeService(rockContext).Queryable().ToList(); var definedTypeList = new DefinedTypeService(rockContext).Queryable().ToList(); var definedValueList = new DefinedValueService(rockContext).Queryable().ToList(); //check if category exists string category = row["CategoryName"] as string; if (categoryList.Find(c => c.Name == category) == null) { var entityType = new EntityTypeService(rockContext); //creates if category doesn't exist var newCategory = new Category(); newCategory.IsSystem = false; newCategory.EntityTypeId = entityType.Queryable().Where(e => e.Name == "Rock.Model.Attribute").Select(e => e.Id).FirstOrDefault(); newCategory.EntityTypeQualifierColumn = "EntityTypeId"; newCategory.EntityTypeQualifierValue = Convert.ToString(PersonEntityTypeId); //Convert.ToString(entityType.Queryable().Where( e => e.Name == "Rock.Model.Person" ).Select( e => e.Id ).FirstOrDefault()); newCategory.Name = category; newCategory.Description = "Contains the spiritual gifts attributes"; //var newCategoryContext = new RockContext(); //newCategoryContext.WrapTransaction( () => //{ // newCategoryContext.Configuration.AutoDetectChangesEnabled = false; // newCategoryContext.Categories.Add( newCategory ); // newCategoryContext.SaveChanges( DisableAudit ); //} ); rockContext.WrapTransaction(() => { rockContext.Configuration.AutoDetectChangesEnabled = false; rockContext.Categories.Add(newCategory); rockContext.SaveChanges(DisableAudit); }); } //Check if Attribute exists if (attributeList.Find(a => a.Key == "Rank1") == null || attributeList.Find(a => a.Key == "Rank2") == null || attributeList.Find(a => a.Key == "Rank3") == null || attributeList.Find(a => a.Key == "Rank4") == null) { var fieldType = new FieldTypeService(rockContext); var newAttributeList = new List <Rock.Model.Attribute>(); var fieldTypeId = fieldType.Queryable().Where(e => e.Name == "Defined Value").FirstOrDefault().Id; var category2 = new CategoryService(rockContext).Queryable().Where(gt => gt.Name == "Spiritual Gifts").FirstOrDefault(); if (attributeList.Find(a => a.Key == "Rank1") == null) { //Creates if attribute doesn't exist var newAttribute = new Rock.Model.Attribute(); newAttribute.Key = "Rank1"; newAttribute.Name = "Rank 1"; newAttribute.FieldTypeId = fieldTypeId; newAttribute.EntityTypeId = PersonEntityTypeId; newAttribute.EntityTypeQualifierValue = string.Empty; newAttribute.EntityTypeQualifierColumn = string.Empty; newAttribute.Description = "Rank 1"; newAttribute.DefaultValue = string.Empty; newAttribute.IsMultiValue = false; newAttribute.IsRequired = false; newAttribute.Categories = new List <Category>(); newAttribute.Categories.Add(category2); newAttributeList.Add(newAttribute); } if (attributeList.Find(a => a.Key == "Rank2") == null) { //Creates if attribute doesn't exist var newAttribute = new Rock.Model.Attribute(); newAttribute.Key = "Rank2"; newAttribute.Name = "Rank 2"; newAttribute.FieldTypeId = fieldTypeId; newAttribute.EntityTypeId = PersonEntityTypeId; newAttribute.EntityTypeQualifierValue = string.Empty; newAttribute.EntityTypeQualifierColumn = string.Empty; newAttribute.Description = "Rank 2"; newAttribute.DefaultValue = string.Empty; newAttribute.IsMultiValue = false; newAttribute.IsRequired = false; newAttribute.Categories = new List <Category>(); newAttribute.Categories.Add(category2); newAttributeList.Add(newAttribute); } if (attributeList.Find(a => a.Key == "Rank3") == null) { //Creates if attribute doesn't exist var newAttribute = new Rock.Model.Attribute(); newAttribute.Key = "Rank3"; newAttribute.Name = "Rank 3"; newAttribute.FieldTypeId = fieldTypeId; newAttribute.EntityTypeId = PersonEntityTypeId; newAttribute.EntityTypeQualifierValue = string.Empty; newAttribute.EntityTypeQualifierColumn = string.Empty; newAttribute.Description = "Rank 3"; newAttribute.DefaultValue = string.Empty; newAttribute.IsMultiValue = false; newAttribute.IsRequired = false; newAttribute.Categories = new List <Category>(); newAttribute.Categories.Add(category2); newAttributeList.Add(newAttribute); } if (attributeList.Find(a => a.Key == "Rank4") == null) { //Creates if attribute doesn't exist var newAttribute = new Rock.Model.Attribute(); newAttribute.Key = "Rank4"; newAttribute.Name = "Rank 4"; newAttribute.FieldTypeId = fieldTypeId; newAttribute.EntityTypeId = PersonEntityTypeId; newAttribute.EntityTypeQualifierValue = string.Empty; newAttribute.EntityTypeQualifierColumn = string.Empty; newAttribute.Description = "Rank 4"; newAttribute.DefaultValue = string.Empty; newAttribute.IsMultiValue = false; newAttribute.IsRequired = false; newAttribute.Categories = new List <Category>(); newAttribute.Categories.Add(category2); newAttributeList.Add(newAttribute); } if (newAttributeList.Any()) { //var newAttributeContext = new RockContext(); rockContext.WrapTransaction(() => { rockContext.Configuration.AutoDetectChangesEnabled = false; rockContext.Attributes.AddRange(newAttributeList); rockContext.SaveChanges(DisableAudit); newAttributeList.Clear(); }); } } //checks if Defined Type exists if (definedTypeList.Find(d => d.Name == "Spiritual Gifts") == null) { var fieldTypeService = new FieldTypeService(rockContext); //creates Defined Type var newDefinedType = new DefinedType(); newDefinedType.IsSystem = false; newDefinedType.FieldTypeId = fieldTypeService.Queryable().Where(f => f.Name == "Text").Select(f => f.Id).FirstOrDefault(); newDefinedType.Name = "Spiritual Gifts"; newDefinedType.Description = "Defined Type for Spiritual Gifts values"; newDefinedType.CategoryId = categoryList.Find(c => c.Name == "Person").Id; //var newDTContext = new RockContext(); rockContext.WrapTransaction(() => { rockContext.Configuration.AutoDetectChangesEnabled = false; rockContext.DefinedTypes.Add(newDefinedType); rockContext.SaveChanges(DisableAudit); }); } //checks if Defined Value exists var spiritualGiftsDefineType = new DefinedTypeService(rockContext).Queryable().Where(d => d.Name == "Spiritual Gifts").FirstOrDefault(); string attributeName = row["AttributeName"] as string; int? giftAttributeId = row["GiftAttributeID"] as int?; if (definedValueList.Find(d => d.DefinedTypeId == spiritualGiftsDefineType.Id && d.Value == attributeName) == null) { var definedTypeService = new DefinedTypeService(rockContext); //creates Defined Value var newDefinedValue = new DefinedValue(); newDefinedValue.IsSystem = false; newDefinedValue.DefinedTypeId = definedTypeService.Queryable().Where(d => d.Name == "Spiritual Gifts").Select(d => d.Id).FirstOrDefault(); newDefinedValue.Value = attributeName; newDefinedValue.Description = "Spiritual Gift attribute value: " + attributeName; newDefinedValue.ForeignId = Convert.ToString(giftAttributeId); //var newDVContext = new RockContext(); rockContext.WrapTransaction(() => { rockContext.Configuration.AutoDetectChangesEnabled = false; rockContext.DefinedValues.Add(newDefinedValue); rockContext.SaveChanges(DisableAudit); }); } completed++; if (completed % percentage < 1) { int percentComplete = completed / percentage; ReportProgress(percentComplete, string.Format("{0:N0} spiritual gifts attributes imported ({1}% complete).", completed, percentComplete)); } else if (completed % ReportingNumber < 1) { ReportPartialProgress(); } } ReportProgress(100, string.Format("Finished spiritual gifts import: {0:N0} spiritual gifts attributes imported.", completed)); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> public void ShowDetail( string itemKey, int itemKeyValue ) { if ( !itemKey.Equals( "definedTypeId" ) ) { return; } pnlDetails.Visible = true; DefinedType definedType = null; if ( !itemKeyValue.Equals( 0 ) ) { definedType = new DefinedTypeService().Get( itemKeyValue ); } else { definedType = new DefinedType { Id = 0 }; definedType.FieldTypeId = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT ).Id; } hfDefinedTypeId.SetValue( definedType.Id ); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if ( !IsUserAuthorized( "Edit" ) ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( DefinedType.FriendlyTypeName ); } if ( definedType.IsSystem ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( DefinedType.FriendlyTypeName ); } if ( readOnly ) { btnEdit.Visible = false; ShowReadonlyDetails( definedType ); } else { btnEdit.Visible = true; if ( definedType.Id > 0 ) { ShowReadonlyDetails( definedType ); } else { ShowEditDetails( definedType ); } } BindDefinedTypeAttributesGrid(); }
/// <summary> /// Adds a new defined value to a given DefinedType. /// </summary> /// <param name="stringValue">the string value of the new defined value</param> /// <param name="definedType">a defined type to which the defined value will be added.</param> /// <param name="rockContext"></param> /// <returns></returns> private DefinedValue AddDefinedTypeValue( string stringValue, DefinedType definedType, RockContext rockContext ) { DefinedValueService definedValueService = new DefinedValueService( rockContext ); DefinedTypeService definedTypeService = new DefinedTypeService( rockContext ); DefinedValue definedValue = new DefinedValue { Id = 0, IsSystem = false, Value = stringValue, Description = string.Empty, CreatedDateTime = RockDateTime.Now, DefinedTypeId = definedType.Id }; definedValueService.Add( definedValue ); rockContext.ChangeTracker.DetectChanges(); rockContext.SaveChanges( disablePrePostProcessing: true ); return definedValue; }
/// <summary> /// Process all the data in the XML file; deleting stuff and then adding stuff. /// as per https://github.com/SparkDevNetwork/Rock/wiki/z.-Rock-Solid-Demo-Church-Specification#wiki-xml-data /// </summary> /// <param name="sampleXmlFile"></param> private void ProcessXml( string sampleXmlFile ) { var xdoc = XDocument.Load( sampleXmlFile ); RockContext rockContext = new RockContext(); rockContext.Configuration.AutoDetectChangesEnabled = false; DefinedTypeService definedTypeService = new DefinedTypeService( rockContext ); _maritalStatusDefinedType = definedTypeService.Get( Rock.SystemGuid.DefinedType.PERSON_MARITAL_STATUS.AsGuid() ); _smallGroupTopicDefinedType = definedTypeService.Get( Rock.SystemGuid.DefinedType.SMALL_GROUP_TOPIC.AsGuid() ); _recordStatusReasonDefinedType = definedTypeService.Get( Rock.SystemGuid.DefinedType.PERSON_RECORD_STATUS_REASON.AsGuid() ); _suffixDefinedType = definedTypeService.Get( Rock.SystemGuid.DefinedType.PERSON_SUFFIX.AsGuid() ); var elemFamilies = xdoc.Element( "data" ).Element( "families" ); var elemGroups = xdoc.Element( "data" ).Element( "groups" ); var elemRelationships = xdoc.Element( "data" ).Element( "relationships" ); var elemConnections = xdoc.Element( "data" ).Element( "connections" ); var elemFollowing = xdoc.Element( "data" ).Element( "following" ); var elemSecurityGroups = xdoc.Element( "data" ).Element( "securityRoles" ); var elemRegistrationTemplates = xdoc.Element( "data" ).Element( "registrationTemplates" ); var elemRegistrationInstances = xdoc.Element( "data" ).Element( "registrationInstances" ); TimeSpan ts; //// First delete any sample data that might exist already // using RockContext in case there are multiple saves (like Attributes) rockContext.WrapTransaction( () => { _stopwatch.Start(); AppendFormat( "00:00.00 started <br/>" ); // Delete this stuff that might have people attached to it DeleteRegistrationTemplates( elemRegistrationTemplates, rockContext ); // Now we'll clean up by deleting any previously created data such as // families, addresses, people, photos, attendance data, etc. DeleteExistingGroups( elemGroups, rockContext ); DeleteExistingFamilyData( elemFamilies, rockContext ); //rockContext.ChangeTracker.DetectChanges(); //rockContext.SaveChanges( disablePrePostProcessing: true ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} data deleted <br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); } ); // make sure the database auth MEF component is initialized in case it hasn't done its first Load/Save Attributes yet (prevents possible lockup) var authenticationComponent = Rock.Security.AuthenticationContainer.GetComponent( EntityTypeCache.Read(_authenticationDatabaseEntityTypeId).Name ); // Import the sample data // using RockContext in case there are multiple saves (like Attributes) rockContext.WrapTransaction( () => { // Now we can add the families (and people) and then groups. AddFamilies( elemFamilies, rockContext ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} families added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); AddRelationships( elemRelationships, rockContext ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} relationships added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); AddGroups( elemGroups, rockContext ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} groups added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); AddConnections( elemConnections, rockContext ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} people connection requests added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); AddFollowing( elemFollowing, rockContext ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} people following added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); AddToSecurityGroups( elemSecurityGroups, rockContext ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} people added to security roles<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); // Add Registration Templates AddRegistrationTemplates( elemRegistrationTemplates, rockContext ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} registration templates added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); // Add Registration Instances AddRegistrationInstances( elemRegistrationInstances, rockContext ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} registration instances added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); rockContext.ChangeTracker.DetectChanges(); rockContext.SaveChanges( disablePrePostProcessing: true ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} changes saved<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); // add logins, but only if we were supplied a password if ( !string.IsNullOrEmpty( tbPassword.Text.Trim() ) ) { AddPersonLogins( rockContext ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} person logins added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); } // Add Person Notes AddPersonNotes( elemFamilies, rockContext ); rockContext.SaveChanges( disablePrePostProcessing: true ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} notes added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); // Add Person Previous LastNames AddPeoplesPreviousNames( elemFamilies, rockContext ); rockContext.SaveChanges( disablePrePostProcessing: true ); ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} previous names added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); // Add Person Metaphone/Sounds-like stuff AddMetaphone(); } ); // done. ts = _stopwatch.Elapsed; AppendFormat( "{0:00}:{1:00}.{2:00} done.<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 ); if ( GetAttributeValue( "EnableStopwatch" ).AsBoolean() ) { lStopwatchLog.Text = _sb.ToString(); } // Clear the static objects that contains all security roles and auth rules (so that it will be refreshed) foreach ( var role in Rock.Security.Role.AllRoles() ) { Rock.Security.Role.Flush(role.Id); } Rock.Security.Authorization.Flush(); }
/// <summary> /// Gets or adds a new DefinedValue to the given DefinedTypeCache and returns the Id of the value. /// </summary> /// <param name="theValue">The value.</param> /// <param name="aDefinedType">a definedTypeCache.</param> /// <param name="rockContext">The rock context.</param> /// <returns>the id of the defined value</returns> private int GetOrAddDefinedValueId( string theValue, DefinedType aDefinedType, RockContext rockContext ) { DefinedValue theDefinedValue = aDefinedType.DefinedValues.FirstOrDefault( a => String.Equals( a.Value, theValue, StringComparison.CurrentCultureIgnoreCase ) ); // add it as new if we didn't find it. if ( theDefinedValue == null ) { theDefinedValue = AddDefinedTypeValue( theValue, aDefinedType, rockContext ); } return theDefinedValue.Id; }
/// <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 ); }
private static Type Load_OnTypeResolve(DefinedType arg) { //return typeof(ResX); return(null); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="definedTypeId">The defined type identifier.</param> public void ShowDetail( int definedTypeId ) { pnlDetails.Visible = true; DefinedType definedType = null; if ( !definedTypeId.Equals( 0 ) ) { definedType = new DefinedTypeService( new RockContext() ).Get( definedTypeId ); } if ( definedType == null ) { definedType = new DefinedType { Id = 0 }; } hfDefinedTypeId.SetValue( definedType.Id ); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if ( _isStandAlone ) { readOnly = true; } else { if ( !IsUserAuthorized( Authorization.EDIT ) ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( DefinedType.FriendlyTypeName ); } if ( definedType.IsSystem ) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( DefinedType.FriendlyTypeName ); } } if ( readOnly ) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails( definedType ); } else { btnEdit.Visible = true; btnDelete.Visible = false; if ( definedType.Id > 0 ) { ShowReadonlyDetails( definedType ); } else { ShowEditDetails( definedType ); } } BindDefinedTypeAttributesGrid(); }
public int? Save(string category, string name, string description = null, bool isSystem = false, int? fieldTypeId = 1, int order = 0, string foreignId = null, string helpText = null, int definedTypeId = 0 ) { DefinedTypeController controller = new DefinedTypeController( Service ); DefinedType definedType = null; if(definedTypeId > 0) { definedType = controller.GetById( definedTypeId ); if(definedType == null || definedType == default(DefinedType)) { return null; } } else { definedType = new DefinedType(); } definedType.IsSystem = isSystem; definedType.FieldTypeId = fieldTypeId; definedType.Order = order; //definedType.Category = category; definedType.Name = name; definedType.Description = description; definedType.ForeignId = foreignId; definedType.HelpText = helpText; if ( definedTypeId > 0 ) { definedType.ModifiedByPersonAliasId = Service.LoggedInPerson.PrimaryAliasId; controller.Update( definedType ); } else { definedType.CreatedByPersonAliasId = Service.LoggedInPerson.PrimaryAliasId; controller.Add( definedType ); } definedType = controller.GetByGuid( definedType.Guid ); return definedType.Id; }
/// <summary> /// Shows the detail. /// </summary> /// <param name="definedTypeId">The defined type identifier.</param> public void ShowDetail(int definedTypeId) { pnlDetails.Visible = true; DefinedType definedType = null; if (!definedTypeId.Equals(0)) { definedType = new DefinedTypeService(new RockContext()).Get(definedTypeId); pdAuditDetails.SetEntity(definedType, ResolveRockUrl("~")); } if (definedType == null) { definedType = new DefinedType { Id = 0 }; // hide the panel drawer that show created and last modified dates pdAuditDetails.Visible = false; } hfDefinedTypeId.SetValue(definedType.Id); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if (_isStandAlone) { readOnly = true; } else { if (!IsUserAuthorized(Authorization.EDIT)) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(DefinedType.FriendlyTypeName); } if (definedType.IsSystem) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(DefinedType.FriendlyTypeName); } } if (readOnly) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails(definedType); } else { btnEdit.Visible = true; btnDelete.Visible = false; if (definedType.Id > 0) { ShowReadonlyDetails(definedType); } else { ShowEditDetails(definedType); } } BindDefinedTypeAttributesGrid(); }
/// <summary> /// Maps the Giftedness Program. /// </summary> /// <param name="tableData">The table data.</param> private void MapGiftednessProgram( IQueryable<Row> tableData ) { int completed = 0; int totalRows = tableData.Count(); int percentage = ( totalRows - 1 ) / 100 + 1; ReportProgress( 0, string.Format( "Verifying Giftedness Program import ({0:N0} found).", totalRows ) ); foreach ( var row in tableData ) { var rockContext = new RockContext(); var categoryList = new CategoryService( rockContext ).Queryable().ToList(); var attributeList = new AttributeService( rockContext ).Queryable().ToList(); var definedTypeList = new DefinedTypeService( rockContext ).Queryable().ToList(); var definedValueList = new DefinedValueService( rockContext ).Queryable().ToList(); //check if category exists string category = row["CategoryName"] as string; if ( categoryList.Find( c => c.Name == category ) == null ) { var entityType = new EntityTypeService( rockContext ); //creates if category doesn't exist var newCategory = new Category(); newCategory.IsSystem = false; newCategory.EntityTypeId = entityType.Queryable().Where( e => e.Name == "Rock.Model.Attribute" ).Select( e => e.Id ).FirstOrDefault(); newCategory.EntityTypeQualifierColumn = "EntityTypeId"; newCategory.EntityTypeQualifierValue = Convert.ToString( PersonEntityTypeId ); //Convert.ToString(entityType.Queryable().Where( e => e.Name == "Rock.Model.Person" ).Select( e => e.Id ).FirstOrDefault()); newCategory.Name = category; newCategory.Description = "Contains the spiritual gifts attributes"; //var newCategoryContext = new RockContext(); //newCategoryContext.WrapTransaction( () => //{ // newCategoryContext.Configuration.AutoDetectChangesEnabled = false; // newCategoryContext.Categories.Add( newCategory ); // newCategoryContext.SaveChanges( DisableAudit ); //} ); rockContext.WrapTransaction( () => { rockContext.Configuration.AutoDetectChangesEnabled = false; rockContext.Categories.Add( newCategory ); rockContext.SaveChanges( DisableAudit ); } ); } //Check if Attribute exists if ( attributeList.Find( a => a.Key == "Rank1" ) == null || attributeList.Find( a => a.Key == "Rank2" ) == null || attributeList.Find( a => a.Key == "Rank3" ) == null || attributeList.Find( a => a.Key == "Rank4" ) == null ) { var fieldType = new FieldTypeService( rockContext ); var newAttributeList = new List<Rock.Model.Attribute>(); var fieldTypeId = fieldType.Queryable().Where( e => e.Name == "Defined Value" ).FirstOrDefault().Id; var category2 = new CategoryService( rockContext ).Queryable().Where( gt => gt.Name == "Spiritual Gifts" ).FirstOrDefault(); if ( attributeList.Find( a => a.Key == "Rank1" ) == null ) { //Creates if attribute doesn't exist var newAttribute = new Rock.Model.Attribute(); newAttribute.Key = "Rank1"; newAttribute.Name = "Rank 1"; newAttribute.FieldTypeId = fieldTypeId; newAttribute.EntityTypeId = PersonEntityTypeId; newAttribute.EntityTypeQualifierValue = string.Empty; newAttribute.EntityTypeQualifierColumn = string.Empty; newAttribute.Description = "Rank 1"; newAttribute.DefaultValue = string.Empty; newAttribute.IsMultiValue = false; newAttribute.IsRequired = false; newAttribute.Categories = new List<Category>(); newAttribute.Categories.Add( category2 ); newAttributeList.Add( newAttribute ); } if ( attributeList.Find( a => a.Key == "Rank2" ) == null ) { //Creates if attribute doesn't exist var newAttribute = new Rock.Model.Attribute(); newAttribute.Key = "Rank2"; newAttribute.Name = "Rank 2"; newAttribute.FieldTypeId = fieldTypeId; newAttribute.EntityTypeId = PersonEntityTypeId; newAttribute.EntityTypeQualifierValue = string.Empty; newAttribute.EntityTypeQualifierColumn = string.Empty; newAttribute.Description = "Rank 2"; newAttribute.DefaultValue = string.Empty; newAttribute.IsMultiValue = false; newAttribute.IsRequired = false; newAttribute.Categories = new List<Category>(); newAttribute.Categories.Add( category2 ); newAttributeList.Add( newAttribute ); } if ( attributeList.Find( a => a.Key == "Rank3" ) == null ) { //Creates if attribute doesn't exist var newAttribute = new Rock.Model.Attribute(); newAttribute.Key = "Rank3"; newAttribute.Name = "Rank 3"; newAttribute.FieldTypeId = fieldTypeId; newAttribute.EntityTypeId = PersonEntityTypeId; newAttribute.EntityTypeQualifierValue = string.Empty; newAttribute.EntityTypeQualifierColumn = string.Empty; newAttribute.Description = "Rank 3"; newAttribute.DefaultValue = string.Empty; newAttribute.IsMultiValue = false; newAttribute.IsRequired = false; newAttribute.Categories = new List<Category>(); newAttribute.Categories.Add( category2 ); newAttributeList.Add( newAttribute ); } if ( attributeList.Find( a => a.Key == "Rank4" ) == null ) { //Creates if attribute doesn't exist var newAttribute = new Rock.Model.Attribute(); newAttribute.Key = "Rank4"; newAttribute.Name = "Rank 4"; newAttribute.FieldTypeId = fieldTypeId; newAttribute.EntityTypeId = PersonEntityTypeId; newAttribute.EntityTypeQualifierValue = string.Empty; newAttribute.EntityTypeQualifierColumn = string.Empty; newAttribute.Description = "Rank 4"; newAttribute.DefaultValue = string.Empty; newAttribute.IsMultiValue = false; newAttribute.IsRequired = false; newAttribute.Categories = new List<Category>(); newAttribute.Categories.Add( category2 ); newAttributeList.Add( newAttribute ); } if ( newAttributeList.Any() ) { //var newAttributeContext = new RockContext(); rockContext.WrapTransaction( () => { rockContext.Configuration.AutoDetectChangesEnabled = false; rockContext.Attributes.AddRange( newAttributeList ); rockContext.SaveChanges( DisableAudit ); newAttributeList.Clear(); } ); } } //checks if Defined Type exists if ( definedTypeList.Find( d => d.Name == "Spiritual Gifts" ) == null ) { var fieldTypeService = new FieldTypeService( rockContext ); //creates Defined Type var newDefinedType = new DefinedType(); newDefinedType.IsSystem = false; newDefinedType.FieldTypeId = fieldTypeService.Queryable().Where( f => f.Name == "Text" ).Select( f => f.Id ).FirstOrDefault(); newDefinedType.Name = "Spiritual Gifts"; newDefinedType.Description = "Defined Type for Spiritual Gifts values"; newDefinedType.CategoryId = categoryList.Find( c => c.Name == "Person" ).Id; //var newDTContext = new RockContext(); rockContext.WrapTransaction( () => { rockContext.Configuration.AutoDetectChangesEnabled = false; rockContext.DefinedTypes.Add( newDefinedType ); rockContext.SaveChanges( DisableAudit ); } ); } //checks if Defined Value exists var spiritualGiftsDefineType = new DefinedTypeService( rockContext ).Queryable().Where( d => d.Name == "Spiritual Gifts" ).FirstOrDefault(); string attributeName = row["AttributeName"] as string; int? giftAttributeId = row["GiftAttributeID"] as int?; if ( definedValueList.Find( d => d.DefinedTypeId == spiritualGiftsDefineType.Id && d.Value == attributeName ) == null ) { var definedTypeService = new DefinedTypeService( rockContext ); //creates Defined Value var newDefinedValue = new DefinedValue(); newDefinedValue.IsSystem = false; newDefinedValue.DefinedTypeId = definedTypeService.Queryable().Where( d => d.Name == "Spiritual Gifts" ).Select( d => d.Id ).FirstOrDefault(); newDefinedValue.Value = attributeName; newDefinedValue.Description = "Spiritual Gift attribute value: " + attributeName; newDefinedValue.ForeignId = Convert.ToString(giftAttributeId); //var newDVContext = new RockContext(); rockContext.WrapTransaction( () => { rockContext.Configuration.AutoDetectChangesEnabled = false; rockContext.DefinedValues.Add( newDefinedValue ); rockContext.SaveChanges( DisableAudit ); } ); } completed++; if ( completed % percentage < 1 ) { int percentComplete = completed / percentage; ReportProgress( percentComplete, string.Format( "{0:N0} spiritual gifts attributes imported ({1}% complete).", completed, percentComplete ) ); } else if ( completed % ReportingNumber < 1 ) { ReportPartialProgress(); } } ReportProgress( 100, string.Format( "Finished spiritual gifts import: {0:N0} spiritual gifts attributes imported.", completed ) ); }
/// <summary> /// Shows the readonly details. /// </summary> /// <param name="definedType">Type of the defined.</param> private void ShowReadonlyDetails( DefinedType definedType ) { SetEditMode( false ); hfDefinedTypeId.SetValue( definedType.Id ); tbTypeName.Text = definedType.Name; definedType.FieldType = definedType.FieldType ?? new FieldTypeService().Get( definedType.FieldTypeId ?? 0 ); lTitle.Text = definedType.Name.FormatAsHtmlTitle(); lDescription.Text = definedType.Description; lblMainDetails.Text = new DescriptionList() .Add("Category", definedType.Category) .Add("FieldType", definedType.FieldType.Name) .Html; definedType.LoadAttributes(); }
public TypeParameter(string name, DefinedType type) : base(name) { Type = type; }
/// <summary> /// Shows the edit details. /// </summary> /// <param name="definedType">Type of the defined.</param> private void ShowEditDetails( DefinedType definedType ) { if ( definedType.Id > 0 ) { lActionTitle.Text = ActionTitle.Edit( DefinedType.FriendlyTypeName ).FormatAsHtmlTitle(); } else { lActionTitle.Text = ActionTitle.Add( DefinedType.FriendlyTypeName ).FormatAsHtmlTitle(); } SetEditMode( true ); tbTypeName.Text = definedType.Name; tbTypeCategory.Text = definedType.Category; tbTypeDescription.Text = definedType.Description; tbHelpText.Text = definedType.HelpText; }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> public void ShowDetail( string itemKey, int itemKeyValue ) { if ( !itemKey.Equals( "definedTypeId" ) ) { return; } pnlList.Visible = true; DefinedType definedType = null; if ( !itemKeyValue.Equals( 0 ) ) { definedType = new DefinedTypeService().Get( itemKeyValue ); } else { definedType = new DefinedType { Id = 0 }; } hfDefinedTypeId.SetValue( definedType.Id ); BindDefinedValuesGrid(); }
string GetAutocomplete(string json) { /* * Format: * textDocument * caret * caret.line * caret.character */ PosData posData = GetPosData(json); if (posData == null) { return(null); } List <CompletionItem> completion = new List <CompletionItem>(); if (posData.SelectedNode != null) { switch (posData.SelectedNode.FirstOrDefault()) { // Ruleset case RulesetNode rulesetNode: completion.AddRange(new CompletionItem[] { new CompletionItem("rule") { kind = CompletionItem.Keyword, textEdit = TextEdit.Insert(posData.Caret, Extras.Lines( "rule: \"My Rule\"", "Event.OngoingGlobal", "{", "}" )) }, new CompletionItem("define") { kind = CompletionItem.Keyword }, new CompletionItem("method") { kind = CompletionItem.Keyword, textEdit = TextEdit.Insert(posData.Caret, Extras.Lines( "method myMethod()", "{", "}" )) } }); break; // Rule node case RuleNode ruleNode: // Event type if (ruleNode.IsEventOptionSelected(posData.Caret)) { completion.AddRange(EnumData.GetEnum <RuleEvent>().GetCompletion()); } // Player else if (ruleNode.IsPlayerOptionSelected(posData.Caret)) { completion.AddRange(EnumData.GetEnum <PlayerSelector>().GetCompletion()); } // Team else if (ruleNode.IsTeamOptionSelected(posData.Caret)) { completion.AddRange(EnumData.GetEnum <Team>().GetCompletion()); } else if (ruleNode.IsIfSelected(posData.Caret)) { completion.AddRange(Element.GetCompletion(true, false)); } else { completion.AddRange(new CompletionItem[] { new CompletionItem("Event") { kind = CompletionItem.Enum }, new CompletionItem("Team") { kind = CompletionItem.Enum }, new CompletionItem("Player") { kind = CompletionItem.Enum }, }); } break; // Actions case BlockNode blockNode: // Get all action methods completion.AddRange(Element.GetCompletion(true, true)); completion.AddRange(CustomMethodData.GetCompletion()); if (parserData.Success) { // Get all variables if (blockNode.RelatedScopeGroup != null) { completion.AddRange(blockNode.RelatedScopeGroup.GetCompletionItems(posData.Caret)); } // Get custom methods if (parserData.UserMethods != null) { completion.AddRange(UserMethod.CollectionCompletion(parserData.UserMethods.ToArray())); } // Get structs if (parserData.DefinedTypes != null) { completion.AddRange(DefinedType.CollectionCompletion(parserData.DefinedTypes.ToArray())); } } break; // Values case MethodNode methodNode: completion.AddRange(Element.GetCompletion(true, false)); completion.AddRange(EnumData.GetAllEnumCompletion()); completion.AddRange(CustomMethodData.GetCompletion()); if (parserData.Success) { // Get all variables if (methodNode.RelatedScopeGroup != null) { completion.AddRange(methodNode.RelatedScopeGroup?.GetCompletionItems(posData.Caret)); } // Get custom methods if (parserData.UserMethods != null) { completion.AddRange(UserMethod.CollectionCompletion(parserData.UserMethods.ToArray())); } } break; // If the selected node is a string node, show all strings. case StringNode stringNode: completion.AddRange(Constants.Strings.Select(str => new CompletionItem(str) { kind = CompletionItem.Text } )); break; case EnumNode enumNode: var add = EnumData.GetEnum(enumNode.Type)?.GetCompletion(); if (add != null) { completion.AddRange(add); } break; case ImportNode importNode: string currentPath = importNode.File; string path = Extras.CombinePathWithDotNotation(posData.File, importNode.File); if (path != null) { completion.Add(new CompletionItem("../") { kind = CompletionItem.Folder }); // GetDirectoryName can return null even if path isn't null. path = Path.GetDirectoryName(path); if (path != null) { foreach (string fullDirectoryPath in Directory.GetDirectories(path)) { string directory = new DirectoryInfo(fullDirectoryPath).Name; completion.Add(new CompletionItem(directory) { kind = CompletionItem.Folder }); } foreach (string fullFilePath in Directory.GetFiles(path)) { string file = Path.GetFileName(fullFilePath); completion.Add(new CompletionItem(file) { kind = CompletionItem.File }); } } } break; } } return(JsonConvert.SerializeObject(completion.ToArray())); }
/// <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 ); }
public DefinedTypeTemplate(GeneratorSettings settings, DefinedType type) { _settings = settings; _helper = new NamedTypeHelper(type, settings); Type = type; }