예제 #1
0
        /// <summary>
        /// Handles the Delete event of the gLinks 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 gLinks_Delete(object sender, RowEventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                var service      = new DefinedValueService(rockContext);
                var definedValue = service.Get(e.RowKeyId);

                if (definedValue != null)
                {
                    string errorMessage;
                    if (!service.CanDelete(definedValue, out errorMessage))
                    {
                        mdGridWarningValues.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    service.Delete(definedValue);
                    rockContext.SaveChanges();

                    DefinedTypeCache.Flush(definedValue.DefinedTypeId);
                    DefinedValueCache.Flush(definedValue.Id);
                }
            }

            BindGrid();
        }
예제 #2
0
        protected void dlgPackage_SaveClick(object sender, EventArgs e)
        {
            int definedValueId = hfDefinedValueId.Value.AsInteger();

            var definedType = DefinedTypeCache.Read(Rock.SystemGuid.DefinedType.PROTECT_MY_MINISTRY_PACKAGES.AsGuid());

            if (definedType != null)
            {
                using (var rockContext = new RockContext())
                {
                    var service = new DefinedValueService(rockContext);

                    DefinedValue definedValue = null;
                    if (!definedValueId.Equals(0))
                    {
                        definedValue = service.Get(definedValueId);
                    }

                    if (definedValue == null)
                    {
                        definedValue = new DefinedValue();
                        definedValue.DefinedTypeId = definedType.Id;
                        service.Add(definedValue);
                    }

                    definedValue.Value       = tbTitle.Text;
                    definedValue.Description = tbDescription.Text;
                    rockContext.SaveChanges();

                    definedValue.LoadAttributes(rockContext);

                    Guid?dvJurisdicationCodeGuid = null;
                    int? dvJurisdictionCodeId    = ddlMVRJurisdication.SelectedValueAsInt();
                    if (dvJurisdictionCodeId.HasValue && dvJurisdictionCodeId.Value > 0)
                    {
                        var dvJurisdicationCode = DefinedValueCache.Read(dvJurisdictionCodeId.Value);
                        if (dvJurisdicationCode != null)
                        {
                            dvJurisdicationCodeGuid = dvJurisdicationCode.Guid;
                        }
                    }

                    definedValue.SetAttributeValue("PMMPackageName", tbPackageName.Text);
                    definedValue.SetAttributeValue("DefaultCounty", tbDefaultCounty.Text);
                    definedValue.SetAttributeValue("SendHomeCounty", cbSendCounty.Checked.ToString());
                    definedValue.SetAttributeValue("DefaultState", tbDefaultState.Text);
                    definedValue.SetAttributeValue("SendHomeState", cbSendState.Checked.ToString());
                    definedValue.SetAttributeValue("MVRJurisdiction", dvJurisdicationCodeGuid.HasValue ? dvJurisdicationCodeGuid.Value.ToString() : string.Empty);
                    definedValue.SetAttributeValue("SendHomeStateMVR", cbSendStateMVR.Checked.ToString());
                    definedValue.SaveAttributeValues(rockContext);

                    DefinedTypeCache.Flush(definedType.Id);
                    DefinedValueCache.Flush(definedValue.Id);
                }
            }

            BindPackageGrid();

            HideDialog();
        }
예제 #3
0
        /// <summary>
        /// Handles the Delete event of the gDefinedValues 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 gDefinedValues_Delete(object sender, RowEventArgs e)
        {
            var valueService = new DefinedValueService();

            DefinedValue value = valueService.Get((int)e.RowKeyValue);

            DefinedTypeCache.Flush(value.DefinedTypeId);
            DefinedValueCache.Flush(value.Id);

            if (value != null)
            {
                valueService.Delete(value, CurrentPersonId);
                valueService.Save(value, CurrentPersonId);
            }

            BindDefinedValuesGrid();
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (Page.IsPostBack)
            {
                using (var rockContext = new RockContext())
                {
                    var definedValueService = new DefinedValueService(rockContext);

                    foreach (RepeaterItem item in rptrValues.Items)
                    {
                        var hfValue = item.FindControl("hfValue") as HiddenField;
                        var cbValue = item.FindControl("cbValue") as CheckBox;

                        if (hfValue != null && cbValue != null)
                        {
                            var value = definedValueService.Get(hfValue.ValueAsInt());
                            if (value != null)
                            {
                                Helper.LoadAttributes(value);
                                if (value.GetAttributeValue(attributeKey) != cbValue.Checked.ToString())
                                {
                                    value.SetAttributeValue(attributeKey, cbValue.Checked.ToString());
                                    value.SaveAttributeValues(rockContext);
                                    DefinedValueCache.Flush(value.Id);
                                }
                            }
                        }
                    }
                }
            }

            bool wasVisible = this.Visible;

            ShowList();

            if (Page.IsPostBack && wasVisible && this.Visible == false)
            {
                // If last item was just checked do a redirect back to the same page.
                // This is needed to hide the control since content is inside an update
                // panel
                Response.Redirect(CurrentPageReference.BuildUrl(), false);
            }
        }
예제 #5
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (Page.IsPostBack)
            {
                var definedValueService = new DefinedValueService();

                foreach (RepeaterItem item in rptrValues.Items)
                {
                    var hfValue = item.FindControl("hfValue") as HiddenField;
                    var cbValue = item.FindControl("cbValue") as CheckBox;

                    if (hfValue != null && cbValue != null)
                    {
                        var value = definedValueService.Get(hfValue.ValueAsInt());
                        if (value != null)
                        {
                            Helper.LoadAttributes(value);
                            value.SetAttributeValue(attributeKey, cbValue.Checked.ToString());
                            Helper.SaveAttributeValues(value, CurrentPersonId);
                            DefinedValueCache.Flush(value.Id);
                        }
                    }
                }
            }

            ShowList();

            if (Page.IsPostBack && pnlContent.Visible == false)
            {
                // If last item was just checked (postback and visible == false),
                // do a redirect back to the same page.  This is needed to hide
                // the pre/post content which is outside of this controls update panel.
                Response.Redirect(CurrentPageReference.BuildUrl(), false);
            }
        }
예제 #6
0
        /// <summary>
        /// Displays the edit list.
        /// </summary>
        private void DisplayEditList()
        {
            lEditHeader.Text = GetAttributeValue("EditHeader");
            lEditFooter.Text = GetAttributeValue("EditFooter");

            if (_definedType != null)
            {
                using (var rockContext = new RockContext())
                {
                    var entityType  = EntityTypeCache.Read("Rock.Model.DefinedValue");
                    var definedType = new DefinedTypeService(rockContext).Get(_definedType.Id);
                    if (definedType != null && entityType != null)
                    {
                        var attributeService = new AttributeService(rockContext);
                        var attributes       = new AttributeService(rockContext)
                                               .Get(entityType.Id, "DefinedTypeId", definedType.Id.ToString())
                                               .ToList();

                        // Verify (and create if neccessary) the "Is Link" attribute
                        if (!attributes.Any(a => a.Key == "IsLink"))
                        {
                            var fieldType = FieldTypeCache.Read(Rock.SystemGuid.FieldType.BOOLEAN);
                            if (entityType != null && fieldType != null)
                            {
                                var attribute = new Rock.Model.Attribute();
                                attributeService.Add(attribute);
                                attribute.EntityTypeId = entityType.Id;
                                attribute.EntityTypeQualifierColumn = "DefinedTypeId";
                                attribute.EntityTypeQualifierValue  = definedType.Id.ToString();
                                attribute.FieldTypeId  = fieldType.Id;
                                attribute.Name         = "Is Link";
                                attribute.Key          = "IsLink";
                                attribute.Description  = "Flag indicating if value is a link (vs Header)";
                                attribute.IsGridColumn = true;
                                attribute.DefaultValue = true.ToString();

                                var qualifier1 = new AttributeQualifier();
                                qualifier1.Key   = "truetext";
                                qualifier1.Value = "Yes";
                                attribute.AttributeQualifiers.Add(qualifier1);

                                var qualifier2 = new AttributeQualifier();
                                qualifier2.Key   = "falsetext";
                                qualifier2.Value = "No";
                                attribute.AttributeQualifiers.Add(qualifier2);

                                rockContext.SaveChanges();

                                DefinedTypeCache.Flush(definedType.Id);
                                foreach (var dv in definedType.DefinedValues)
                                {
                                    DefinedValueCache.Flush(dv.Id);
                                }
                            }
                        }
                    }
                }

                BindGrid();

                pnlView.Visible = false;
                pnlEdit.Visible = true;
            }
        }