private static int LoadByGuid2(Guid guid, RockContext rockContext)
        {
            var personBadgeService = new PersonBadgeService(rockContext);

            return(personBadgeService
                   .Queryable().AsNoTracking()
                   .Where(c => c.Guid.Equals(guid))
                   .Select(c => c.Id)
                   .FirstOrDefault());
        }
Beispiel #2
0
        void gPersonBadge_GridReorder(object sender, GridReorderEventArgs e)
        {
            var rockContext  = new RockContext();
            var service      = new PersonBadgeService(rockContext);
            var personBadges = service.Queryable().OrderBy(b => b.Order);

            service.Reorder(personBadges.ToList(), e.OldIndex, e.NewIndex);
            rockContext.SaveChanges();

            BindGrid();
        }
Beispiel #3
0
        private static PersonBadgeCache LoadById2(int id, RockContext rockContext)
        {
            var personBadgeService = new PersonBadgeService(rockContext);
            var personBadgeModel   = personBadgeService.Get(id);

            if (personBadgeModel != null)
            {
                return(new PersonBadgeCache(personBadgeModel));
            }

            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            PersonBadge        PersonBadge        = null;
            var                rockContext        = new RockContext();
            PersonBadgeService PersonBadgeService = new PersonBadgeService(rockContext);

            if (PersonBadgeId != 0)
            {
                PersonBadge = PersonBadgeService.Get(PersonBadgeId);
            }

            if (PersonBadge == null)
            {
                PersonBadge = new PersonBadge();
                PersonBadgeService.Add(PersonBadge);
            }

            PersonBadge.Name        = tbName.Text;
            PersonBadge.Description = tbDescription.Text;

            if (!string.IsNullOrWhiteSpace(compBadgeType.SelectedValue))
            {
                var badgeType = EntityTypeCache.Read(compBadgeType.SelectedValue.AsGuid());
                if (badgeType != null)
                {
                    PersonBadge.EntityTypeId = badgeType.Id;
                }
            }

            PersonBadge.LoadAttributes(rockContext);
            Rock.Attribute.Helper.GetEditValues(phAttributes, PersonBadge);

            if (!Page.IsValid)
            {
                return;
            }

            if (!PersonBadge.IsValid)
            {
                return;
            }

            rockContext.WrapTransaction(() =>
            {
                rockContext.SaveChanges();
                PersonBadge.SaveAttributeValues(rockContext);
            });

            PersonBadgeCache.Flush(PersonBadge.Id);

            NavigateToParentPage();
        }
        /// <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)
            {
                lActionTitle.Text = ActionTitle.Add(PersonBadge.FriendlyTypeName).FormatAsHtmlTitle();

                PersonBadgeId = PageParameter("PersonBadgeId").AsInteger();
                if (PersonBadgeId != 0)
                {
                    var personBadge = new PersonBadgeService(new RockContext()).Get(PersonBadgeId);
                    if (personBadge != null)
                    {
                        lActionTitle.Text = ActionTitle.Edit(personBadge.Name).FormatAsHtmlTitle();

                        tbName.Text        = personBadge.Name;
                        tbDescription.Text = personBadge.Description;
                        if (personBadge.EntityTypeId.HasValue)
                        {
                            var badgeType = EntityTypeCache.Read(personBadge.EntityTypeId.Value);
                            compBadgeType.SelectedValue = badgeType.Guid.ToString().ToUpper();
                        }

                        BuildEditControls(personBadge, true);
                        pdAuditDetails.SetEntity(personBadge, ResolveRockUrl("~"));
                    }
                }
                else
                {
                    // hide the panel drawer that show created and last modified dates
                    pdAuditDetails.Visible = false;
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(compBadgeType.SelectedValue))
                {
                    var badgeType = EntityTypeCache.Read(compBadgeType.SelectedValue.AsGuid());
                    if (badgeType != null)
                    {
                        var personBadge = new PersonBadge {
                            EntityTypeId = badgeType.Id
                        };
                        BuildEditControls(personBadge, false);
                    }
                }
            }
        }
        /// <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)
            {
                lActionTitle.Text = ActionTitle.Add(PersonBadge.FriendlyTypeName).FormatAsHtmlTitle();

                PersonBadgeId = PageParameter("PersonBadgeId").AsInteger() ?? 0;
                if (PersonBadgeId != 0)
                {
                    var personBadge = new PersonBadgeService(new RockContext()).Get(PersonBadgeId);
                    if (personBadge != null)
                    {
                        lActionTitle.Text = ActionTitle.Edit(personBadge.Name).FormatAsHtmlTitle();

                        tbName.Text        = personBadge.Name;
                        tbDescription.Text = personBadge.Description;
                        if (personBadge.EntityTypeId.HasValue)
                        {
                            var badgeType = EntityTypeCache.Read(personBadge.EntityTypeId.Value);
                            compBadgeType.SelectedValue = badgeType.Guid.ToString().ToUpper();
                        }

                        BuildEditControls(personBadge, true);
                    }
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(compBadgeType.SelectedValue))
                {
                    var badgeType = EntityTypeCache.Read(compBadgeType.SelectedValue.AsGuid());
                    if (badgeType != null)
                    {
                        var personBadge = new PersonBadge {
                            EntityTypeId = badgeType.Id
                        };
                        BuildEditControls(personBadge, false);
                    }
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Handles the Delete event of the gPersonBadge 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 gPersonBadge_Delete(object sender, RowEventArgs e)
        {
            var rockContext = new RockContext();
            PersonBadgeService personBadgeService = new PersonBadgeService(rockContext);
            PersonBadge        personBadge        = personBadgeService.Get(e.RowKeyId);

            if (personBadge != null)
            {
                string errorMessage;
                if (!personBadgeService.CanDelete(personBadge, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                personBadgeService.Delete(personBadge);
                rockContext.SaveChanges();
            }

            BindGrid();
        }