示例#1
0
        /// <summary>
        /// Sets the selected location.
        /// Note this will redirect to the current page to include a LocationId query parameter if a LocationId parameter in the URL is missing or doesn't match.
        /// </summary>
        /// <param name="rockBlock">The rock block.</param>
        /// <param name="lpLocation">The lp location.</param>
        /// <param name="locationId">The identifier of the location.</param>
        /// <param name="campusId">The campus identifier.</param>
        public static void SetSelectedLocation(RockBlock rockBlock, LocationPicker lpLocation, int?locationId, int campusId)
        {
            if (locationId.HasValue && locationId > 0)
            {
                CheckinManagerHelper.SaveCampusLocationConfigurationToCookie(campusId, locationId);
                var pageParameterLocationId = rockBlock.PageParameter(PageParameterKey.LocationId).AsIntegerOrNull();
                if (!pageParameterLocationId.HasValue || pageParameterLocationId.Value != locationId)
                {
                    var additionalQueryParameters = new Dictionary <string, string>();
                    additionalQueryParameters.Add(PageParameterKey.LocationId, locationId.ToString());
                    rockBlock.NavigateToCurrentPageReference(additionalQueryParameters);
                    return;
                }

                using (var rockContext = new RockContext())
                {
                    if (locationId.HasValue)
                    {
                        lpLocation.SetNamedLocation(NamedLocationCache.Get(locationId.Value));
                    }
                }
            }
            else
            {
                lpLocation.Location = null;
                CheckinManagerHelper.SaveCampusLocationConfigurationToCookie(campusId, null);
            }
        }
示例#2
0
        /// <summary>
        /// Gets the selected location.
        /// </summary>
        /// <param name="rockBlock">The rock block.</param>
        /// <param name="campus">The campus.</param>
        /// <param name="lpLocation">The lp location.</param>
        /// <returns></returns>
        public static int?GetSelectedLocation(RockBlock rockBlock, CampusCache campus, LocationPicker lpLocation)
        {
            // If the Campus selection has changed, we need to reload the LocationItemPicker with the Locations specific to that Campus.
            lpLocation.NamedPickerRootLocationId = campus.LocationId.GetValueOrDefault();

            // Check the LocationPicker for the Location ID.
            int locationId = lpLocation.NamedLocation?.Id ?? 0;

            if (locationId > 0)
            {
                return(locationId);
            }

            // If not defined on the LocationPicker, check first for a LocationId Page parameter.
            locationId = rockBlock.PageParameter(PageParameterKey.LocationId).AsInteger();

            if (locationId > 0)
            {
                // double check the locationId in the URL is valid for the Campus (just in case it was altered or is no longer valid for the campus)
                var locationCampusId = NamedLocationCache.Get(locationId).CampusId;
                if (locationCampusId != campus.Id)
                {
                    locationId = 0;
                }
            }

            if (locationId > 0)
            {
                CheckinManagerHelper.SaveCampusLocationConfigurationToCookie(campus.Id, locationId);
            }
            else
            {
                // If still not defined, check for cookie setting.
                locationId = CheckinManagerHelper.GetCheckinManagerConfigurationFromCookie().LocationIdFromSelectedCampusId.GetValueOrNull(campus.Id) ?? 0;

                if (locationId > 0)
                {
                    // double check the locationId in the cookie is valid for the Campus (just in case it was altered or is no longer valid for the campus)
                    var locationCampusId = NamedLocationCache.Get(locationId)?.CampusId;
                    if (locationCampusId != campus.Id)
                    {
                        locationId = 0;
                    }
                }

                if (locationId <= 0)
                {
                    return(null);
                }
            }

            return(locationId);
        }