Пример #1
0
        /// <summary>
        /// Handles the Delete event of the gCampuses 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 gCampuses_Delete(object sender, RowEventArgs e)
        {
            var           rockContext   = new RockContext();
            CampusService campusService = new CampusService(rockContext);
            Campus        campus        = campusService.Get(e.RowKeyId);

            if (campus != null)
            {
                // Don't allow deleting the last campus
                if (!campusService.Queryable().Where(c => c.Id != campus.Id).Any())
                {
                    mdGridWarning.Show(campus.Name + " is the only campus and cannot be deleted (Rock requires at least one campus).", ModalAlertType.Information);
                    return;
                }

                string errorMessage;
                if (!campusService.CanDelete(campus, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                CampusCache.Flush(campus.Id);

                campusService.Delete(campus);
                rockContext.SaveChanges();
            }

            BindGrid();
        }
Пример #2
0
 // Flush any cached campus that uses location
 private void FlushCampus(int locationId)
 {
     foreach (var campus in CampusCache.All()
              .Where(c => c.LocationId == locationId))
     {
         CampusCache.Flush(campus.Id);
     }
 }
Пример #3
0
        /// <summary>
        /// Handles the GridReorder event of the gCampuses control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridReorderEventArgs"/> instance containing the event data.</param>
        protected void gCampuses_GridReorder(object sender, GridReorderEventArgs e)
        {
            var rockContext = new RockContext();
            var campuses    = GetCampuses(rockContext).ToList();

            if (campuses != null)
            {
                new CampusService(rockContext).Reorder(campuses, e.OldIndex, e.NewIndex);
                rockContext.SaveChanges();

                campuses.ForEach(t => CampusCache.Flush(t.Id));
            }

            BindGrid();
        }