Exemple #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);
            }
        }
Exemple #2
0
        /// <summary>
        /// Sets the value from location identifier.
        /// </summary>
        /// <param name="locationId">The location identifier.</param>
        public void SetValueFromLocationId(int?locationId)
        {
            if (locationId != null && locationId > 0)
            {
                ItemId = locationId.ToString();
                var                location          = NamedLocationCache.Get(locationId.Value);
                List <int>         parentLocationIds = new List <int>();
                NamedLocationCache parentLocation    = location?.ParentLocation;

                while (parentLocation != null)
                {
                    if (parentLocationIds.Contains(parentLocation.Id))
                    {
                        // infinite recursion
                        break;
                    }

                    parentLocationIds.Insert(0, parentLocation.Id);
                    parentLocation = parentLocation.ParentLocation;
                }

                InitialItemParentIds = parentLocationIds.AsDelimited(",");
                ItemName             = location?.Name;
            }
            else
            {
                ItemId   = Constants.None.IdValue;
                ItemName = Constants.None.TextHtml;
            }
        }
Exemple #3
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="namedLocation">The named location.</param>
        public void SetValueFromNamedLocation(NamedLocationCache namedLocation)
        {
            if (namedLocation != null)
            {
                ItemId = namedLocation.Id.ToString();
                List <int> parentLocationIds = new List <int>();
                var        parentLocation    = namedLocation.ParentLocation;

                while (parentLocation != null)
                {
                    if (parentLocationIds.Contains(parentLocation.Id))
                    {
                        // infinite recursion
                        break;
                    }

                    parentLocationIds.Insert(0, parentLocation.Id);
                    parentLocation = parentLocation.ParentLocation;
                }

                InitialItemParentIds = parentLocationIds.AsDelimited(",");
                ItemName             = namedLocation.Name;
            }
            else
            {
                ItemId   = Constants.None.IdValue;
                ItemName = Constants.None.TextHtml;
            }
        }
        /// <summary>
        /// Restores view-state information from a previous request that was saved with the <see cref="M:System.Web.UI.WebControls.WebControl.SaveViewState" /> method.
        /// </summary>
        /// <param name="savedState">An object that represents the control state to restore.</param>
        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);

            var currentPickerMode = ViewState["CurrentPickerMode"] as LocationPickerMode?;

            if (currentPickerMode.HasValue)
            {
                this.CurrentPickerMode = currentPickerMode.Value;
            }

            var locationId = ViewState["LocationId"] as int?;

            if (locationId.HasValue)
            {
                if (currentPickerMode == LocationPickerMode.Named)
                {
                    SetNamedLocation(NamedLocationCache.Get(locationId.Value));
                }
                else
                {
                    var location = new LocationService(new RockContext()).Get(locationId.Value);
                    if (location != null)
                    {
                        this.Location = location;
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Sets the values on select.
        /// </summary>
        protected override void SetValuesOnSelect()
        {
            var ids   = this.SelectedValuesAsInt().ToList();
            var items = ids.Select(a => NamedLocationCache.Get(a)).Where(a => a != null).ToList();

            this.SetValuesFromNamedLocations(items);
        }
Exemple #6
0
        /// <summary>
        /// Handles the SaveClick event of the mdMovePerson 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 mdMovePerson_SaveClick(object sender, EventArgs e)
        {
            var attendanceId = ddlMovePersonSelectAttendance.SelectedValueAsId();

            if (attendanceId == null)
            {
                return;
            }

            var rockContext                 = new RockContext();
            var attendanceService           = new AttendanceService(rockContext);
            var attendanceOccurrenceService = new AttendanceOccurrenceService(rockContext);
            var attendance = attendanceService.Get(attendanceId.Value);

            if (attendance == null)
            {
                return;
            }

            var selectedOccurrenceDate = attendance.Occurrence.OccurrenceDate;
            var selectedScheduleId     = ddlMovePersonSchedule.SelectedValueAsId();
            var selectedLocationId     = lpMovePersonLocation.SelectedValueAsId();
            var selectedGroupId        = ddlMovePersonGroup.SelectedValueAsId();

            if (!selectedLocationId.HasValue || !selectedGroupId.HasValue || !selectedScheduleId.HasValue)
            {
                return;
            }

            var location = NamedLocationCache.Get(selectedLocationId.Value);

            var locationFirmRoomThreshold = location?.FirmRoomThreshold;

            if (locationFirmRoomThreshold.HasValue)
            {
                // The totalAttended is the number of people still checked in (not people who have been checked-out)
                // not counting the current person who may already be checked in,
                // + the person we are trying to move
                var locationCount = attendanceService.GetByDateOnLocationAndSchedule(selectedOccurrenceDate, selectedLocationId.Value, selectedScheduleId.Value)
                                    .Where(a => a.EndDateTime == null && a.PersonAlias.PersonId != attendance.PersonAlias.PersonId).Count();

                if ((locationCount + 1) >= locationFirmRoomThreshold.Value)
                {
                    nbMovePersonLocationFull.Text    = $"The {location} has reached its hard threshold capacity and cannot be used for check-in.";
                    nbMovePersonLocationFull.Visible = true;
                    return;
                }
            }

            var newRoomsOccurrence = attendanceOccurrenceService.GetOrAdd(selectedOccurrenceDate, selectedGroupId, selectedLocationId, selectedScheduleId);

            attendance.OccurrenceId = newRoomsOccurrence.Id;
            rockContext.SaveChanges();

            mdMovePerson.Hide();
            BindGrid();
        }
Exemple #7
0
        /// <summary>
        /// Gets the cache object associated with this Entity
        /// </summary>
        /// <returns></returns>
        public IEntityCache GetCacheObject()
        {
            if (this.Name.IsNotNullOrWhiteSpace())
            {
                return(NamedLocationCache.Get(this.Id));
            }

            return(null);
        }
Exemple #8
0
        /// <summary>
        /// Gets the CampusID associated with the Location from the location or from the location's parent path
        /// </summary>
        /// <param name="locationId">The location identifier.</param>
        /// <returns></returns>
        public int?GetCampusIdForLocation(int?locationId)
        {
            if (!locationId.HasValue)
            {
                return(null);
            }

            return(NamedLocationCache.Get(locationId.Value).GetCampusIdForLocation());
        }
Exemple #9
0
 public void SetValue(Rock.Model.Location location)
 {
     if (location != null)
     {
         SetValueFromNamedLocation(NamedLocationCache.Get(location));
     }
     else
     {
         SetValueFromNamedLocation(( NamedLocationCache )null);
     }
 }
Exemple #10
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);
        }
Exemple #11
0
        private static KioskLocationAttendance Create(int id)
        {
            using (var rockContext = new Rock.Data.RockContext())
            {
                var location = NamedLocationCache.Get(id);
                if (location == null)
                {
                    return(null);
                }

                var locationAttendance = new KioskLocationAttendance();
                locationAttendance.LocationId   = location.Id;
                locationAttendance.LocationName = location.Name;
                locationAttendance.Groups       = new List <KioskGroupAttendance>();

                var attendanceService = new AttendanceService(rockContext);

                var todayDate = RockDateTime.Today.Date;

                var attendanceList = attendanceService.Queryable()
                                     .Where(a =>
                                            a.Occurrence.OccurrenceDate == todayDate &&
                                            a.Occurrence.LocationId == location.Id &&
                                            a.Occurrence.GroupId.HasValue &&
                                            a.Occurrence.LocationId.HasValue &&
                                            a.Occurrence.ScheduleId.HasValue &&
                                            a.PersonAliasId.HasValue &&
                                            a.DidAttend.HasValue &&
                                            a.DidAttend.Value &&
                                            !a.EndDateTime.HasValue)
                                     .Select(a => new AttendanceInfo
                {
                    EndDateTime   = a.EndDateTime,
                    StartDateTime = a.StartDateTime,
                    CampusId      = a.CampusId,
                    GroupId       = a.Occurrence.GroupId,
                    GroupName     = a.Occurrence.Group.Name,
                    Schedule      = a.Occurrence.Schedule,
                    PersonId      = a.PersonAlias.PersonId
                })
                                     .AsNoTracking()
                                     .ToList();

                foreach (var attendance in attendanceList)
                {
                    AddAttendanceRecord(locationAttendance, attendance);
                }

                return(locationAttendance);
            }
        }
Exemple #12
0
        /// <summary>
        /// Updates any Cache Objects that are associated with this entity
        /// </summary>
        /// <param name="entityState">State of the entity.</param>
        /// <param name="dbContext">The database context.</param>
        public void UpdateCache(EntityState entityState, Rock.Data.DbContext dbContext)
        {
            // Make sure CampusCache.All is cached using the dbContext (to avoid deadlock if snapshot isolation is disabled)
            var campusId = this.GetCampusId(dbContext as RockContext);

            NamedLocationCache.FlushItem(this.Id);

            // CampusCache has a CampusLocation that could get stale when Location changes, so refresh the CampusCache for this location's Campus
            if (this.CampusId.HasValue)
            {
                CampusCache.UpdateCachedEntity(this.CampusId.Value, EntityState.Detached);
            }

            // and also refresh the CampusCache for any Campus that uses this location
            foreach (var campus in CampusCache.All(dbContext as RockContext).Where(c => c.LocationId == this.Id))
            {
                CampusCache.UpdateCachedEntity(campus.Id, EntityState.Detached);
            }
        }
Exemple #13
0
        /// <summary>
        /// Sets the attendance-specific properties.
        /// </summary>
        /// <param name="attendance">The attendance.</param>
        /// <param name="checkinAreaPathsLookup">The checkin area paths lookup.</param>
        private void SetAttendanceInfo(RosterAttendeeAttendance attendance, Dictionary <int, CheckinAreaPath> checkinAreaPathsLookup)
        {
            // Keep track of each Attendance ID tied to this Attendee so we can manage them all as a group.
            this.Attendances.Add(attendance, true);

            // Tag(s).
            string tag = attendance.AttendanceCode;

            if (tag.IsNotNullOrWhiteSpace() && !this.UniqueTags.Contains(tag, StringComparer.OrdinalIgnoreCase))
            {
                this.UniqueTags.Add(tag);
            }

            // Service Time(s).
            string serviceTime = attendance.Schedule?.Name;

            if (serviceTime.IsNotNullOrWhiteSpace() && !this.UniqueServiceTimes.Contains(serviceTime, StringComparer.OrdinalIgnoreCase))
            {
                this.UniqueServiceTimes.Add(serviceTime);
            }

            // Status: if this Attendee has multiple Attendances, the most recent attendaces
            var latestAttendance = this.Attendances
                                   .OrderByDescending(a => a.StartDateTime)
                                   .First();

            this.Statuses = this.Attendances.Select(s => GetRosterAttendeeStatus(s.EndDateTime, s.PresentDateTime)).ToArray();

            // If this Attendee has multiple Attendances, use the DateTime from the most recent
            this.CheckInTime     = latestAttendance.StartDateTime;
            this.PresentDateTime = latestAttendance.PresentDateTime;
            this.CheckOutTime    = latestAttendance.EndDateTime;

            this.GroupTypeId = latestAttendance.GroupTypeId;

            this.GroupName = latestAttendance.GroupName;

            // GroupId should have a value, but just in case, we'll do some null safety.
            this.GroupId = latestAttendance.GroupId ?? 0;

            if (GroupTypeId.HasValue)
            {
                this.GroupTypePath = checkinAreaPathsLookup.GetValueOrNull(GroupTypeId.Value)?.Path;
            }

            this.ParentGroupId          = latestAttendance.ParentGroupId;
            this.ParentGroupName        = latestAttendance.ParentGroupName;
            this.ParentGroupGroupTypeId = latestAttendance.ParentGroupGroupTypeId;
            if (this.ParentGroupGroupTypeId.HasValue)
            {
                this.ParentGroupGroupTypePath = checkinAreaPathsLookup.GetValueOrNull(ParentGroupGroupTypeId.Value)?.Path;
            }

            this.IsFirstTime = latestAttendance?.IsFirstTime ?? false;

            // ScheduleId should have a value, but just in case, we'll do some null safety.
            this.ScheduleId = latestAttendance.ScheduleId ?? 0;

            this._parentsNames = latestAttendance.ParentsNames;

            this.ScheduleIds = this.Attendances.Select(a => a.ScheduleId ?? 0).Distinct().ToArray();

            this.RoomName = NamedLocationCache.Get(latestAttendance.LocationId ?? 0)?.Name;
        }
Exemple #14
0
 public void SetValues(IEnumerable <Location> locations)
 {
     SetValuesFromNamedLocations(locations.Select(a => NamedLocationCache.Get(a)).ToList());
 }
 /// <summary>
 /// Sets the named location.
 /// Does nothing if <seealso cref="CurrentPickerMode"/> is not <seealso cref="LocationPickerMode.Named"/>
 /// </summary>
 /// <param name="namedLocation">The named location.</param>
 public void SetNamedLocation(NamedLocationCache namedLocation)
 {
     _namedPicker?.SetValueFromLocationId(namedLocation?.Id);
 }
            /// <summary>
            /// Method that will be called on an entity immediately before the item is saved by context
            /// </summary>
            protected override void PreSave()
            {
                PersonAttendanceHistoryChangeList = new History.HistoryChangeList();

                _isDeleted = State == EntityContextState.Deleted;
                bool previousDidAttendValue;

                bool previouslyDeclined;

                if (State == EntityContextState.Added)
                {
                    previousDidAttendValue = false;
                    previouslyDeclined     = false;
                }
                else
                {
                    // get original values so we can detect whether the value changed
                    previousDidAttendValue = ( bool )Entry.OriginalValues.GetReadOnlyValueOrDefault("DidAttend", false);
                    previouslyDeclined     = (Entry.OriginalValues.GetReadOnlyValueOrDefault("RSVP", null) as RSVP? ) == RSVP.No;
                }

                // if the record was changed to Declined, queue a GroupScheduleCancellationTransaction in PostSaveChanges
                _declinedScheduledAttendance = (previouslyDeclined == false) && Entity.IsScheduledPersonDeclined();

                if (previousDidAttendValue == false && Entity.DidAttend == true)
                {
                    var launchMemberAttendedGroupWorkflowMsg = GetLaunchMemberAttendedGroupWorkflowMessage();
                    launchMemberAttendedGroupWorkflowMsg.Send();
                }

                var attendance = this.Entity;

                if (State == EntityContextState.Modified)
                {
                    preSavePersonAliasId = attendance.PersonAliasId;
                    var originalOccurrenceId = ( int? )OriginalValues[nameof(attendance.OccurrenceId)];
                    if (originalOccurrenceId.HasValue && attendance.OccurrenceId != originalOccurrenceId.Value)
                    {
                        var attendanceOccurrenceService = new AttendanceOccurrenceService(this.RockContext);
                        var originalOccurrence          = attendanceOccurrenceService.GetNoTracking(originalOccurrenceId.Value);
                        var currentOccurrence           = attendanceOccurrenceService.GetNoTracking(attendance.OccurrenceId);
                        if (originalOccurrence != null && currentOccurrence != null)
                        {
                            if (originalOccurrence.GroupId != currentOccurrence.GroupId)
                            {
                                History.EvaluateChange(PersonAttendanceHistoryChangeList, "Group", originalOccurrence.Group?.Name, currentOccurrence.Group?.Name);
                            }

                            if (originalOccurrence.ScheduleId.HasValue && currentOccurrence.ScheduleId.HasValue && originalOccurrence.ScheduleId.Value != currentOccurrence.ScheduleId.Value)
                            {
                                History.EvaluateChange(PersonAttendanceHistoryChangeList, "Schedule", NamedScheduleCache.Get(originalOccurrence.ScheduleId.Value)?.Name, NamedScheduleCache.Get(currentOccurrence.ScheduleId.Value)?.Name);
                            }

                            if (originalOccurrence.LocationId.HasValue && currentOccurrence.LocationId.HasValue && originalOccurrence.LocationId.Value != currentOccurrence.LocationId.Value)
                            {
                                History.EvaluateChange(PersonAttendanceHistoryChangeList, "Location", NamedLocationCache.Get(originalOccurrence.LocationId.Value)?.Name, NamedLocationCache.Get(currentOccurrence.LocationId.Value)?.Name);
                            }
                        }
                    }
                }
                else if (State == EntityContextState.Deleted)
                {
                    preSavePersonAliasId = ( int? )OriginalValues[nameof(attendance.PersonAliasId)];
                    PersonAttendanceHistoryChangeList.AddChange(History.HistoryVerb.Delete, History.HistoryChangeType.Record, "Attendance");
                }

                base.PreSave();
            }