Beispiel #1
0
        /// <summary>
        /// Reads the specified GUID.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        public static CampusCache Read(Guid guid)
        {
            ObjectCache cache    = MemoryCache.Default;
            object      cacheObj = cache[guid.ToString()];

            if (cacheObj != null)
            {
                return(Read((int)cacheObj));
            }
            else
            {
                var campusService = new CampusService();
                var campusModel   = campusService.Get(guid);
                if (campusModel != null)
                {
                    campusModel.LoadAttributes();
                    var campus = new CampusCache(campusModel);

                    var cachePolicy = new CacheItemPolicy();
                    cache.Set(CampusCache.CacheKey(campus.Id), campus, cachePolicy);
                    cache.Set(campus.Guid.ToString(), campus.Id, cachePolicy);

                    return(campus);
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #2
0
        private void Load(CampusData c)
        {
            Init();
            if (c != null)
            {
                CampusService campusService = new CampusService(new Rock.Data.RockContext());

                Rock.Model.Campus RockCampus = campusService.Get(c.campus_id);
                Id = RockCampus.Id;
                CreatedDateTime         = RockCampus.CreatedDateTime;
                ModifiedDateTime        = RockCampus.ModifiedDateTime;
                CreatedByPersonAliasId  = RockCampus.CreatedByPersonAliasId;
                ModifiedByPersonAliasId = RockCampus.ModifiedByPersonAliasId;
                Guid = RockCampus.Guid;
                Name = RockCampus.Name;
                LeaderPersonAliasId = RockCampus.LeaderPersonAliasId;
                LocationId          = RockCampus.LocationId;
                CompanyID           = c.campus_company_id;
                FundID           = c.campus_fund_id;
                XrefDateCreated  = c.date_created;
                XrefCreatedBy    = c.created_by;
                XrefDateModified = c.date_modified;
                XrefModifiedBy   = c.modified_by;
                XrefActive       = c.active;
            }
        }
        /// <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();
        }
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)
        {
            Campus        campus;
            CampusService campusService = new CampusService();

            int campusId = int.Parse(hfCampusId.Value);

            if (campusId == 0)
            {
                campus = new Campus();
                campusService.Add(campus, CurrentPersonId);
            }
            else
            {
                campus = campusService.Get(campusId);
            }

            campus.Name      = tbCampusName.Text;
            campus.ShortCode = tbCampusCode.Text;

            if (!campus.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            RockTransactionScope.WrapTransaction(() =>
            {
                campusService.Save(campus, CurrentPersonId);
            });

            NavigateToParentPage();
        }
Beispiel #5
0
        /// <summary>
        /// Returns Campus object from cache.  If campus does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static CampusCache Read(int id)
        {
            string cacheKey = CampusCache.CacheKey(id);

            ObjectCache cache  = MemoryCache.Default;
            CampusCache campus = cache[cacheKey] as CampusCache;

            if (campus != null)
            {
                return(campus);
            }
            else
            {
                CampusService campusService = new CampusService();
                Campus        campusModel   = campusService.Get(id);
                if (campusModel != null)
                {
                    campusModel.LoadAttributes();
                    campus = new CampusCache(campusModel);

                    var cachePolicy = new CacheItemPolicy();
                    cache.Set(cacheKey, campus, cachePolicy);
                    cache.Set(campus.Guid.ToString(), campus.Id, cachePolicy);

                    return(campus);
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #6
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)
        {
            Campus campus;
            var    rockContext     = new RockContext();
            var    campusService   = new CampusService(rockContext);
            var    locationService = new LocationService(rockContext);

            int campusId = int.Parse(hfCampusId.Value);

            if (campusId == 0)
            {
                campus = new Campus();
                campusService.Add(campus);
                var orders = campusService.Queryable()
                             .Select(t => t.Order)
                             .ToList();

                campus.Order = orders.Any() ? orders.Max(t => t) + 1 : 0;
            }
            else
            {
                campus = campusService.Get(campusId);
            }

            campus.Name        = tbCampusName.Text;
            campus.IsActive    = cbIsActive.Checked;
            campus.Description = tbDescription.Text;
            campus.Url         = tbUrl.Text;

            campus.PhoneNumber = tbPhoneNumber.Text;

            lpLocation.Location = campus.Location;

            campus.ShortCode  = tbCampusCode.Text;
            campus.TimeZoneId = ddlTimeZone.SelectedValue;

            var personService = new PersonService(rockContext);
            var leaderPerson  = personService.Get(ppCampusLeader.SelectedValue ?? 0);

            campus.LeaderPersonAliasId = leaderPerson != null ? leaderPerson.PrimaryAliasId : null;

            campus.ServiceTimes = kvlServiceTimes.Value;

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

            if (!campus.IsValid && campus.Location.IsValid)
            {
                // Controls will render the error messages
                return;
            }

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

            NavigateToParentPage();
        }
Beispiel #7
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)
        {
            CampusService campusService = new CampusService();
            Campus        campus        = campusService.Get((int)gCampuses.DataKeys[e.RowIndex]["id"]);

            if (CurrentBlock != null)
            {
                campusService.Delete(campus, CurrentPersonId);
                campusService.Save(campus, CurrentPersonId);
            }

            BindGrid();
        }
Beispiel #8
0
        void rFilter_DisplayFilterValue(object sender, GridFilter.DisplayFilterValueArgs e)
        {
            switch (e.Key)
            {
            case "Campus":

                int campusId = 0;
                if (int.TryParse(e.Value, out campusId))
                {
                    var service = new CampusService();
                    var campus  = service.Get(campusId);
                    if (campus != null)
                    {
                        e.Value = campus.Name;
                    }
                }

                break;
            }
        }
Beispiel #9
0
        /// <summary>
        /// Handles the filter display
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        protected void rAccountFilter_DisplayFilterValue(object sender, GridFilter.DisplayFilterValueArgs e)
        {
            switch (e.Key)
            {
            case "Campus":

                int?campusId = e.Value.AsInteger(false);
                if (campusId.HasValue)
                {
                    var service = new CampusService(new RockContext());
                    var campus  = service.Get(campusId.Value);
                    if (campus != null)
                    {
                        e.Value = campus.Name;
                    }
                }

                break;
            }
        }
        /// <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((int)e.RowKeyValue);

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

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

            BindGrid();
        }
Beispiel #11
0
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="campusId">The campus id.</param>
        protected void ShowEdit(int campusId)
        {
            pnlList.Visible    = false;
            pnlDetails.Visible = true;

            CampusService campusService = new CampusService();
            Campus        campus        = campusService.Get(campusId);

            if (campus != null)
            {
                lActionTitle.Text = ActionTitle.Edit(Campus.FriendlyTypeName);
                hfCampusId.Value  = campus.Id.ToString();
                tbCampusName.Text = campus.Name;
            }
            else
            {
                lActionTitle.Text = ActionTitle.Add(Campus.FriendlyTypeName);
                hfCampusId.Value  = 0.ToString();
                tbCampusName.Text = string.Empty;
            }
        }
Beispiel #12
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)
        {
            Campus        campus;
            var           rockContext   = new RockContext();
            CampusService campusService = new CampusService(rockContext);

            int campusId = int.Parse(hfCampusId.Value);

            if (campusId == 0)
            {
                campus = new Campus();
                campusService.Add(campus);
            }
            else
            {
                campus = campusService.Get(campusId);
            }

            campus.Name        = tbCampusName.Text;
            campus.ShortCode   = tbCampusCode.Text;
            campus.PhoneNumber = tbPhoneNumber.Text;

            var personService = new PersonService(rockContext);
            var leaderPerson  = personService.Get(ppCampusLeader.SelectedValue ?? 0);

            campus.LeaderPersonAliasId = leaderPerson != null ? leaderPerson.PrimaryAliasId : null;

            if (!campus.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            rockContext.SaveChanges();

            Rock.Web.Cache.CampusCache.Flush(campus.Id);

            NavigateToParentPage();
        }
Beispiel #13
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)
        {
            RockTransactionScope.WrapTransaction(() =>
            {
                CampusService campusService = new CampusService();
                Campus campus = campusService.Get((int)e.RowKeyValue);
                if (campus != null)
                {
                    string errorMessage;
                    if (!campusService.CanDelete(campus, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    campusService.Delete(campus, CurrentPersonId);
                    campusService.Save(campus, CurrentPersonId);
                }
            });

            BindGrid();
        }
Beispiel #14
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)
        {
            Campus        campus;
            CampusService campusService = new CampusService();

            int campusId = int.Parse(hfCampusId.Value);;

            if (campusId == 0)
            {
                campus = new Campus();
                campusService.Add(campus, CurrentPersonId);
            }
            else
            {
                campus = campusService.Get(campusId);
            }

            campus.Name = tbCampusName.Text;

            // check for duplicates
            if (campusService.Queryable().Count(a => a.Name.Equals(campus.Name, StringComparison.OrdinalIgnoreCase) && !a.Id.Equals(campus.Id)) > 0)
            {
                nbMessage.Text    = WarningMessage.DuplicateFoundMessage("name", Campus.FriendlyTypeName);
                nbMessage.Visible = true;
                return;
            }

            if (!campus.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            campusService.Save(campus, CurrentPersonId);
            BindGrid();
            pnlDetails.Visible = false;
            pnlList.Visible    = true;
        }
Beispiel #15
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)
        {
            var campusLocationType = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.LOCATION_TYPE_CAMPUS.AsGuid());

            if (campusLocationType.Id != lpLocation.Location.LocationTypeValueId)
            {
                nbEditModeMessage.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Danger;
                nbEditModeMessage.Text = "The selected named location is not a 'Campus' location type. Please update this before continuing.";
                return;
            }

            Campus campus;
            var    rockContext     = new RockContext();
            var    campusService   = new CampusService(rockContext);
            var    locationService = new LocationService(rockContext);

            int campusId = int.Parse(hfCampusId.Value);

            if (campusId == 0)
            {
                campus = new Campus();
                campusService.Add(campus);
                var orders = campusService.Queryable()
                             .Select(t => t.Order)
                             .ToList();

                campus.Order = orders.Any() ? orders.Max(t => t) + 1 : 0;
            }
            else
            {
                campus = campusService.Get(campusId);
            }

            campus.Name                = tbCampusName.Text;
            campus.IsActive            = cbIsActive.Checked;
            campus.Description         = tbDescription.Text;
            campus.CampusStatusValueId = dvpCampusStatus.SelectedValueAsInt();
            campus.CampusTypeValueId   = dvpCampusType.SelectedValueAsInt();
            campus.Url         = tbUrl.Text;
            campus.PhoneNumber = tbPhoneNumber.Text;
            campus.LocationId  = lpLocation.Location.Id;
            campus.ShortCode   = tbCampusCode.Text;
            campus.TimeZoneId  = ddlTimeZone.SelectedValue;

            var personService = new PersonService(rockContext);
            var leaderPerson  = personService.Get(ppCampusLeader.SelectedValue ?? 0);

            campus.LeaderPersonAliasId = leaderPerson != null ? leaderPerson.PrimaryAliasId : null;

            campus.ServiceTimes = kvlServiceTimes.Value;

            avcAttributes.GetEditValues(campus);

            if (!campus.IsValid && campus.Location.IsValid)
            {
                // Controls will render the error messages
                return;
            }

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

            NavigateToParentPage();
        }
Beispiel #16
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)
        {
            if (!ValidateCampus())
            {
                // Error messaging handled by ValidateCampus
                return;
            }

            if (!IsFormValid())
            {
                return;
            }

            Campus campus;
            var    rockContext     = new RockContext();
            var    campusService   = new CampusService(rockContext);
            var    locationService = new LocationService(rockContext);

            int campusId = HiddenCampusId;

            if (campusId == 0)
            {
                campus = new Campus();
                campusService.Add(campus);
                var orders = campusService.Queryable()
                             .AsNoTracking()
                             .Select(t => t.Order)
                             .ToList();

                campus.Order = orders.Any() ? orders.Max(t => t) + 1 : 0;
            }
            else
            {
                campus = campusService.Get(campusId);
            }

            campus.Name                = tbCampusName.Text;
            campus.IsActive            = cbIsActive.Checked;
            campus.Description         = tbDescription.Text;
            campus.CampusStatusValueId = dvpCampusStatus.SelectedValueAsInt();
            campus.CampusTypeValueId   = dvpCampusType.SelectedValueAsInt();
            campus.Url         = urlCampus.Text;
            campus.PhoneNumber = pnbPhoneNumber.Number;
            campus.LocationId  = lpLocation.Location.Id;
            campus.ShortCode   = tbCampusCode.Text;
            campus.TimeZoneId  = ddlTimeZone.SelectedValue;

            var personService = new PersonService(rockContext);
            var leaderPerson  = personService.GetNoTracking(ppCampusLeader.SelectedValue ?? 0);

            campus.LeaderPersonAliasId = leaderPerson != null ? leaderPerson.PrimaryAliasId : null;

            campus.ServiceTimes = kvlServiceTimes.Value;

            avcAttributes.GetEditValues(campus);

            if (!campus.IsValid && campus.Location.IsValid)
            {
                // Controls will render the error messages
                return;
            }

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

            NavigateToCurrentPage(new Dictionary <string, string> {
                { "CampusId", campus.Id.ToString() }
            });
        }
        /// <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 (!ValidateCampus())
            {
                // Error messaging handled by ValidateCampus
                return;
            }

            if (!IsFormValid())
            {
                return;
            }

            Campus campus;
            var    rockContext     = new RockContext();
            var    campusService   = new CampusService(rockContext);
            var    locationService = new LocationService(rockContext);

            int campusId = HiddenCampusId;

            if (campusId == 0)
            {
                campus = new Campus();
                campusService.Add(campus);
                var orders = campusService.Queryable()
                             .AsNoTracking()
                             .Select(t => t.Order)
                             .ToList();

                campus.Order = orders.Any() ? orders.Max(t => t) + 1 : 0;
            }
            else
            {
                campus = campusService.Get(campusId);
            }

            campus.Name                = tbCampusName.Text;
            campus.IsActive            = cbIsActive.Checked;
            campus.Description         = tbDescription.Text;
            campus.CampusStatusValueId = dvpCampusStatus.SelectedValueAsInt();
            campus.CampusTypeValueId   = dvpCampusType.SelectedValueAsInt();
            campus.Url         = urlCampus.Text;
            campus.PhoneNumber = pnbPhoneNumber.Number;
            campus.LocationId  = lpLocation.Location.Id;
            campus.ShortCode   = tbCampusCode.Text;
            campus.TimeZoneId  = ddlTimeZone.SelectedValue;

            var personService = new PersonService(rockContext);
            var leaderPerson  = personService.GetNoTracking(ppCampusLeader.SelectedValue ?? 0);

            campus.LeaderPersonAliasId = leaderPerson != null ? leaderPerson.PrimaryAliasId : null;

            campus.ServiceTimes = kvlServiceTimes.Value;


            // Remove any CampusSchedules that were removed in the UI
            var selectedSchedules = CampusSchedulesState.Select(s => s.Guid);
            var locationsToRemove = campus.CampusSchedules.Where(s => !selectedSchedules.Contains(s.Guid)).ToList();
            CampusScheduleService campusScheduleService = null;

            foreach (var campusSchedule in locationsToRemove)
            {
                campusScheduleService = campusScheduleService ?? new CampusScheduleService(rockContext);
                campus.CampusSchedules.Remove(campusSchedule);
                campusScheduleService.Delete(campusSchedule);
            }

            // Add/Update any CampusSchedules that were added or changed in the UI.
            foreach (var campusScheduleState in CampusSchedulesState)
            {
                var campusSchedule = campus.CampusSchedules.Where(s => s.Guid == campusScheduleState.Guid).FirstOrDefault();
                if (campusSchedule == null)
                {
                    campusSchedule = new CampusSchedule()
                    {
                        CampusId            = campus.Id,
                        ScheduleId          = campusScheduleState.ScheduleId,
                        ScheduleTypeValueId = campusScheduleState.ScheduleTypeId,
                        Order = campusScheduleState.Order,
                        Guid  = Guid.NewGuid()
                    };
                    campus.CampusSchedules.Add(campusSchedule);
                }
                else
                {
                    campusSchedule.ScheduleId          = campusScheduleState.ScheduleId;
                    campusSchedule.ScheduleTypeValueId = campusScheduleState.ScheduleTypeId;
                }
            }

            SaveCampusTopics(campus, rockContext);

            avcAttributes.GetEditValues(campus);

            if (!campus.IsValid && campus.Location.IsValid)
            {
                // Controls will render the error messages
                return;
            }

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

            NavigateToCurrentPage(new Dictionary <string, string> {
                { "CampusId", campus.Id.ToString() }
            });
        }
Beispiel #18
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)
        {
            Campus campus;
            var    rockContext         = new RockContext();
            var    campusService       = new CampusService(rockContext);
            var    locationService     = new LocationService(rockContext);
            var    locationCampusValue = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.LOCATION_TYPE_CAMPUS.AsGuid());

            int campusId = int.Parse(hfCampusId.Value);

            if (campusId == 0)
            {
                campus = new Campus();
                campusService.Add(campus);
            }
            else
            {
                campus = campusService.Get(campusId);
            }

            campus.Name        = tbCampusName.Text;
            campus.IsActive    = cbIsActive.Checked;
            campus.Description = tbDescription.Text;
            campus.Url         = tbUrl.Text;

            campus.PhoneNumber = tbPhoneNumber.Text;
            if (campus.Location == null)
            {
                var location = locationService.Queryable()
                               .Where(l =>
                                      l.Name.Equals(campus.Name, StringComparison.OrdinalIgnoreCase) &&
                                      l.LocationTypeValueId == locationCampusValue.Id)
                               .FirstOrDefault();
                if (location == null)
                {
                    location = new Location();
                    locationService.Add(location);
                }

                campus.Location = location;
            }

            campus.Location.Name = campus.Name;
            campus.Location.LocationTypeValueId = locationCampusValue.Id;

            string preValue = campus.Location.GetFullStreetAddress();

            acAddress.GetValues(campus.Location);
            string postValue = campus.Location.GetFullStreetAddress();

            campus.ShortCode = tbCampusCode.Text;

            var personService = new PersonService(rockContext);
            var leaderPerson  = personService.Get(ppCampusLeader.SelectedValue ?? 0);

            campus.LeaderPersonAliasId = leaderPerson != null ? leaderPerson.PrimaryAliasId : null;

            campus.ServiceTimes = kvlServiceTimes.Value;

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

            if (!campus.IsValid && campus.Location.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            rockContext.WrapTransaction(() =>
            {
                rockContext.SaveChanges();
                campus.SaveAttributeValues(rockContext);

                if (preValue != postValue && !string.IsNullOrWhiteSpace(campus.Location.Street1))
                {
                    locationService.Verify(campus.Location, true);
                }
            });

            Rock.Web.Cache.CampusCache.Flush(campus.Id);

            NavigateToParentPage();
        }
        /// <summary>
        /// Modifies the Rock Solid Finances Class to add multiple schedules and campuses.
        /// </summary>
        private static void InitializeEventRockSolidFinancesClassTestData()
        {
            var rockContext = new RockContext();

            // Add a new campus
            var campusService = new CampusService(rockContext);

            var campus2 = campusService.Get(SecondaryCampusGuidString.AsGuid());

            if (campus2 == null)
            {
                campus2 = new Campus();

                campusService.Add(campus2);
            }

            campus2.Name = "Stepping Stone";
            campus2.Guid = SecondaryCampusGuidString.AsGuid();

            rockContext.SaveChanges();

            // Get existing schedules.
            var scheduleService = new ScheduleService(rockContext);

            var scheduleSat1630Id = scheduleService.GetId(ScheduleSat1630Guid.AsGuid());
            var scheduleSat1800Id = scheduleService.GetId(ScheduleSun1200Guid.AsGuid());

            // Get Event "Rock Solid Finances".
            var eventItemService           = new EventItemService(rockContext);
            var eventItemOccurrenceService = new EventItemOccurrenceService(rockContext);

            var financeEvent = eventItemService.Get(EventFinancesClassGuid.AsGuid());

            // Add an occurrence of this event for each Schedule.
            var financeEvent1 = eventItemOccurrenceService.Get(FinancesClassOccurrenceSat1630Guid.AsGuid());

            if (financeEvent1 == null)
            {
                financeEvent1 = new EventItemOccurrence();
            }

            var mainCampusId   = CampusCache.GetId(MainCampusGuidString.AsGuid());
            var secondCampusId = CampusCache.GetId(SecondaryCampusGuidString.AsGuid());

            financeEvent1.Location   = "Meeting Room 1";
            financeEvent1.ForeignKey = TestDataForeignKey;
            financeEvent1.ScheduleId = scheduleSat1630Id;
            financeEvent1.Guid       = FinancesClassOccurrenceSat1630Guid.AsGuid();
            financeEvent1.CampusId   = mainCampusId;

            financeEvent.EventItemOccurrences.Add(financeEvent1);

            var financeEvent2 = eventItemOccurrenceService.Get(FinancesClassOccurrenceSun1200Guid.AsGuid());

            if (financeEvent2 == null)
            {
                financeEvent2 = new EventItemOccurrence();
            }

            financeEvent2.Location   = "Meeting Room 2";
            financeEvent2.ForeignKey = TestDataForeignKey;
            financeEvent2.ScheduleId = scheduleSat1800Id;
            financeEvent2.Guid       = FinancesClassOccurrenceSun1200Guid.AsGuid();
            financeEvent2.CampusId   = secondCampusId;

            financeEvent.EventItemOccurrences.Add(financeEvent2);

            rockContext.SaveChanges();
        }