コード例 #1
0
        /// <summary>
        /// Handles the Delete event of the gLinkList 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 gLinkList_Delete(object sender, RowEventArgs e)
        {
            var rockContext         = new RockContext();
            var personalLinkService = new PersonalLinkService(rockContext);
            var personalLink        = personalLinkService.Get(e.RowKeyId);

            if (personalLink != null)
            {
                string errorMessage;
                if (!personalLink.IsAuthorized(Authorization.EDIT, CurrentPerson))
                {
                    mdGridWarning.Show("You are not authorized to delete this link", ModalAlertType.Information);
                    return;
                }

                if (!personalLinkService.CanDelete(personalLink, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                personalLinkService.Delete(personalLink);
                rockContext.SaveChanges();
            }

            BindGrid();
        }
コード例 #2
0
        /// <summary>
        /// Binds the connection types repeater.
        /// </summary>
        private void BindSectionDropdown()
        {
            var rockContext         = new RockContext();
            var personalLinkService = new PersonalLinkService(rockContext);
            var sectionsQuery       = personalLinkService.GetOrderedPersonalLinkSectionsQuery(this.CurrentPerson);

            // limit to ones that are non-shared
            var orderedPersonalLinkSections = sectionsQuery
                                              .AsNoTracking()
                                              .ToList()
                                              .Where(a => a.PersonAliasId.HasValue && a.PersonAlias.PersonId == this.CurrentPersonId)
                                              .ToList();

            ddlSection.DataSource     = orderedPersonalLinkSections;
            ddlSection.DataTextField  = "Name";
            ddlSection.DataValueField = "Id";
            ddlSection.DataBind();
            if (orderedPersonalLinkSections.Any())
            {
                ddlSection.Items.Insert(0, new ListItem());
                ddlSection.Required = true;
            }
            else
            {
                // if there aren't any link sections, use a section called 'Links' as a default
                ddlSection.Items.Insert(0, new ListItem("Links"));
                ddlSection.Required = false;
            }
        }
コード例 #3
0
        /// <summary>
        /// Handles the Click event of the btnLinkSave control.
        /// </summary>
        protected void btnLinkSave_Click(object sender, EventArgs e)
        {
            var rockContext         = new RockContext();
            var personalLinkService = new PersonalLinkService(rockContext);
            var sectionId           = ddlSection.SelectedValueAsId();

            if (!sectionId.HasValue)
            {
                sectionId = SaveSection("Links");
            }

            if (sectionId.HasValue)
            {
                var personalLink = new PersonalLink()
                {
                    Id            = 0,
                    SectionId     = sectionId.Value,
                    PersonAliasId = CurrentPersonAliasId.Value,
                    Name          = tbLinkName.Text,
                    Url           = urlLink.Text
                };

                personalLinkService.Add(personalLink);
                rockContext.SaveChanges();

                ShowView();
                pnlView.Visible = true;
            }
        }
コード例 #4
0
        public PersonalLinkService.PersonalLinksData GetPersonalLinksData()
        {
            var currentPerson = this.GetPerson();

            if (currentPerson == null)
            {
                throw new HttpResponseException(System.Net.HttpStatusCode.Unauthorized);
            }

            var updatedPersonalLinksData = PersonalLinkService.GetPersonalLinksData(currentPerson);

            return(updatedPersonalLinksData);
        }
コード例 #5
0
        /// <summary>
        /// Handles the Edit event of the gLinkList 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 gLinkList_Edit(object sender, RowEventArgs e)
        {
            var personalLink = new PersonalLinkService(new RockContext()).Get(e.RowKeyId);

            if (personalLink.PersonAliasId != CurrentPersonAliasId.Value && !personalLink.IsAuthorized(Authorization.EDIT, CurrentPerson))
            {
                mdGridWarning.Show("Not authorized to make changes to this link.", ModalAlertType.Information);
                return;
            }

            tbName.Text            = personalLink.Name;
            urlLink.Text           = personalLink.Url;
            hfPersonalLinkId.Value = personalLink.Id.ToString();

            mdAddPersonalLink.Title = "Edit Personal Link";
            mdAddPersonalLink.Show();
        }
コード例 #6
0
        /// <summary>
        /// Gets the personal links that will be displayed in the grid
        /// </summary>
        /// <returns></returns>
        private List <PersonalLink> GetDataGridList(RockContext rockContext)
        {
            var qry = new PersonalLinkService(rockContext).Queryable().Where(a => a.SectionId == _personalLinkSection.Id);

            // Filter by: Name
            var name = gfFilter.GetUserPreference(UserPreferenceKey.Name).ToStringSafe();

            if (!string.IsNullOrWhiteSpace(name))
            {
                qry = qry.Where(a => a.Name.Contains(name));
            }

            qry = qry.OrderBy(g => g.Order).ThenBy(g => g.Name);

            var dataGridList = qry.ToList()
                               .Where(a => a.IsAuthorized(Rock.Security.Authorization.VIEW, this.CurrentPerson))
                               .ToList();

            return(dataGridList);
        }
コード例 #7
0
        /// <summary>
        /// Handles the SaveClick event of the mdAddPersonalLink 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 mdAddPersonalLink_SaveClick(object sender, EventArgs e)
        {
            var          rockContext         = new RockContext();
            var          personalLinkService = new PersonalLinkService(rockContext);
            PersonalLink personalLink        = null;

            if (hfPersonalLinkId.Value.AsInteger() != 0)
            {
                personalLink = personalLinkService.Get(hfPersonalLinkId.Value.AsInteger());
            }
            else
            {
                personalLink = new PersonalLink
                {
                    SectionId = _personalLinkSection.Id
                };

                // add the new link to the bottom of the list for that section
                var lastLinkOrder = personalLinkService.Queryable().Where(a => a.SectionId == _personalLinkSection.Id).Max(a => ( int? )a.Order) ?? 0;
                personalLink.Order = lastLinkOrder + 1;

                personalLinkService.Add(personalLink);
            }

            if (_personalLinkSection?.IsShared == true)
            {
                personalLink.PersonAliasId = null;
            }
            else
            {
                personalLink.PersonAliasId = CurrentPersonAliasId.Value;
            }

            personalLink.Name = tbName.Text;
            personalLink.Url  = urlLink.Text;
            rockContext.SaveChanges();

            mdAddPersonalLink.Hide();
            BindGrid();
        }
コード例 #8
0
 /// <summary>
 /// Sets the data attributes.
 /// </summary>
 private void SetDataAttributes()
 {
     divPersonalLinks.Attributes[DataAttributeKey.LastSharedLinkUpdateDateTime]  = SharedPersonalLinkSectionCache.LastModifiedDateTime.ToISO8601DateString();
     divPersonalLinks.Attributes[DataAttributeKey.QuickLinksLocalStorageKey]     = PersonalLinkService.GetQuickLinksLocalStorageKey(this.CurrentPerson);
     divPersonalLinks.Attributes[DataAttributeKey.PersonalLinksModificationHash] = PersonalLinkService.GetPersonalLinksModificationHash(this.CurrentPerson);
     upnlContent.Update();
 }
コード例 #9
0
        /// <summary>
        /// Gets the grid data source list (ordered)
        /// </summary>
        /// <returns>List&lt;PersonalLinkSectionViewModel&gt;.</returns>
        private List <PersonalLinkSectionViewModel> GetGridDataSourceList(RockContext rockContext)
        {
            var limitToSharedSections = GetAttributeValue(AttributeKey.SharedSections).AsBoolean();
            List <PersonalLinkSection> personalLinkSectionList;
            Dictionary <int, PersonalLinkSectionOrder> currentPersonSectionOrderLookupBySectionId = null;

            if (limitToSharedSections)
            {
                // only show shared sections in this mode
                var sharedPersonalLinkSectionsQuery = new PersonalLinkSectionService(rockContext).Queryable().Where(a => a.IsShared);
                personalLinkSectionList = sharedPersonalLinkSectionsQuery.Include(a => a.PersonalLinks).OrderBy(a => a.Name).AsNoTracking().ToList();
            }
            else
            {
                // show both shared and non-shared, but don't let shared sections get deleted (even if authorized)
                var personalLinkService = new PersonalLinkService(rockContext);
                if (personalLinkService.AddMissingPersonalLinkSectionOrders(this.CurrentPerson))
                {
                    rockContext.SaveChanges();
                }

                var orderedPersonalLinkSectionsQuery = new PersonalLinkService(rockContext).GetOrderedPersonalLinkSectionsQuery(this.CurrentPerson);

                personalLinkSectionList = orderedPersonalLinkSectionsQuery
                                          .Include(a => a.PersonalLinks)
                                          .AsNoTracking()
                                          .ToList()
                                          .Where(a => a.IsAuthorized(Rock.Security.Authorization.VIEW, this.CurrentPerson))
                                          .ToList();

                // NOTE: We might be making changes when resorting this, so don't use AsNoTracking()
                var sectionOrderQuery = personalLinkService.GetSectionOrderQuery(this.CurrentPerson);
                currentPersonSectionOrderLookupBySectionId = sectionOrderQuery.ToDictionary(k => k.SectionId, v => v);
            }

            gSectionList.EntityTypeId = EntityTypeCache.GetId <PersonalLinkSection>();

            var viewModelList = personalLinkSectionList.Select(a =>
            {
                var personalLinkSectionViewModel = new PersonalLinkSectionViewModel
                {
                    Id        = a.Id,
                    Name      = a.Name,
                    LinkCount = a.PersonalLinks.Where(x => x.IsAuthorized(Rock.Security.Authorization.VIEW, this.CurrentPerson)).Count(),
                    IsShared  = a.IsShared,
                    PersonalLinkSectionOrder = currentPersonSectionOrderLookupBySectionId?.GetValueOrNull(a.Id)
                };

                if (limitToSharedSections)
                {
                    // if we are only showing shared sections, let them edit it if authorized edit
                    personalLinkSectionViewModel.CanEdit = a.IsAuthorized(Authorization.EDIT, CurrentPerson);
                }
                else
                {
                    // Don't allow shared sections to be deleted/edited if we showing both shared and non-shared sections
                    personalLinkSectionViewModel.CanEdit = !a.IsShared;
                }

                personalLinkSectionViewModel.CanDelete = personalLinkSectionViewModel.CanEdit;

                return(personalLinkSectionViewModel);
            }).ToList();

            return(viewModelList.OrderBy(a => a.PersonalLinkSectionOrder?.Order ?? 0).ThenBy(a => a.Name).ToList());
        }