/// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var rockContext         = new RockContext();
            var mediaAccountService = new MediaAccountService(rockContext);

            // Use AsNoTracking() since these records won't be modified, and therefore don't need to be tracked by the EF change tracker
            var qry = mediaAccountService.Queryable().AsNoTracking();

            // name filter
            string nameFilter = gfAccounts.GetUserPreference(UserPreferenceKey.Name);

            if (!string.IsNullOrEmpty(nameFilter))
            {
                qry = qry.Where(account => account.Name.Contains(nameFilter));
            }

            Guid?accountTypeGuid = gfAccounts.GetUserPreference(UserPreferenceKey.AccountType).AsGuidOrNull();

            if (accountTypeGuid.HasValue)
            {
                qry = qry.Where(l => l.ComponentEntityType.Guid.Equals(accountTypeGuid.Value));
            }

            bool showInactiveAccounts = gfAccounts.GetUserPreference(UserPreferenceKey.IncludeInactive).AsBoolean();

            if (!showInactiveAccounts)
            {
                qry = qry.Where(s => s.IsActive == true);
            }

            var selectQry = qry
                            .Select(a => new
            {
                a.Id,
                a.Name,
                Type = a.ComponentEntityType,
                a.LastRefreshDateTime,
                Folders = a.MediaFolders.Count,
                Videos  = a.MediaFolders.SelectMany(b => b.MediaElements).Count()
            });

            var sortProperty = gAccountList.SortProperty;

            if (gAccountList.AllowSorting && sortProperty != null)
            {
                qry = qry.Sort(sortProperty);
            }
            else
            {
                qry = qry.OrderBy(a => a.Name);
            }

            gAccountList.EntityTypeId = EntityTypeCache.GetId <MediaAccount>();
            gAccountList.DataSource   = selectQry.ToList();
            gAccountList.DataBind();
        }
        /// <summary>
        /// Get the actual media account model for deleting or editing
        /// </summary>
        /// <returns></returns>
        private MediaAccount GetMediaAccount(RockContext rockContext = null)
        {
            rockContext = rockContext ?? new RockContext();
            var mediaAccountService = new MediaAccountService(rockContext);

            var mediaAccountId = PageParameter(PageParameterKey.MediaAccountId).AsIntegerOrNull();

            if (!mediaAccountId.HasValue)
            {
                return(null);
            }

            return(mediaAccountService.Queryable().FirstOrDefault(a => a.Id == mediaAccountId.Value));
        }