Beispiel #1
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            RockContext             rockContext             = new RockContext();
            PersistedDatasetService persistedDatasetService = new PersistedDatasetService(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 = persistedDatasetService.Queryable().AsNoTracking();

            var sortProperty = gList.SortProperty;

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

            gList.SetLinqDataSource(qry);
            gList.DataBind();
        }
        /// <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)
        {
            if (!Page.IsValid)
            {
                return;
            }

            var rockContext = new RockContext();
            PersistedDatasetService persistedDatasetService = new PersistedDatasetService(rockContext);

            PersistedDataset persistedDataset;

            int persistedDatasetId = hfPersistedDatasetId.Value.AsInteger();

            if (persistedDatasetId == 0)
            {
                persistedDataset = new PersistedDataset();
                persistedDatasetService.Add(persistedDataset);
            }
            else
            {
                persistedDataset = persistedDatasetService.Get(persistedDatasetId);
            }

            var accessKey = tbAccessKey.Text;

            if (accessKey.IsNullOrWhiteSpace())
            {
                nbAccessKeyWarning.Visible = true;
                nbAccessKeyWarning.Text    = "Access Key cannot be blank";
                return;
            }

            var accessKeyAlreadyExistsForDataSet = persistedDatasetService.Queryable().Where(a => a.AccessKey == accessKey && a.Id != persistedDataset.Id).AsNoTracking().FirstOrDefault();

            if (accessKeyAlreadyExistsForDataSet != null)
            {
                nbAccessKeyWarning.Visible = true;
                nbAccessKeyWarning.Text    = string.Format("Access Key must be unique. {0} is using '{1}' as the access key", accessKeyAlreadyExistsForDataSet.Name, accessKey);
                return;
            }

            persistedDataset.Name                = tbName.Text;
            persistedDataset.IsActive            = cbIsActive.Checked;
            persistedDataset.AccessKey           = tbAccessKey.Text;
            persistedDataset.Description         = tbDescription.Text;
            persistedDataset.BuildScript         = ceBuildScript.Text;
            persistedDataset.EnabledLavaCommands = lcpEnabledLavacommands.SelectedLavaCommands.AsDelimited(",");
            var refreshIntervalHours = nbRefreshIntervalHours.Text.AsDoubleOrNull();

            if (refreshIntervalHours.HasValue)
            {
                persistedDataset.RefreshIntervalMinutes = ( int )TimeSpan.FromHours(refreshIntervalHours.Value).TotalMinutes;
            }
            else
            {
                persistedDataset.RefreshIntervalMinutes = null;
            }

            var memoryCacheDurationHours = nbMemoryCacheDurationHours.Text.AsDoubleOrNull();

            if (memoryCacheDurationHours.HasValue)
            {
                persistedDataset.MemoryCacheDurationMS = ( int )TimeSpan.FromHours(memoryCacheDurationHours.Value).TotalMilliseconds;
            }
            else
            {
                persistedDataset.MemoryCacheDurationMS = null;
            }

            persistedDataset.ExpireDateTime     = dtpExpireDateTime.SelectedDate;
            persistedDataset.EntityTypeId       = etpEntityType.SelectedEntityTypeId;
            persistedDataset.AllowManualRefresh = cbAllowManualRefresh.Checked;

            // just in case anything has changed, null out the LastRefreshDateTime and TimeToBuild to mark this as needing to be refreshed the next time the Persisted Dataset job runs
            persistedDataset.LastRefreshDateTime = null;
            persistedDataset.TimeToBuildMS       = null;

            rockContext.SaveChanges();

            NavigateToParentPage();
        }