public static void AddExitHistory(RockContext rockContext, Location location, Attendance attendeeAttendance, bool isSubroom) { HistoryService historyService = new HistoryService(rockContext); var summary = string.Format("Exited <span class=\"field-name\">{0}</span> at <span class=\"field-name\">{1}</span>", location.Name, Rock.RockDateTime.Now); if (isSubroom) { summary += string.Format(" (a subroom of <span class=\"field-name\">{0}</span>)", location.ParentLocation.Name); } History history = new History() { EntityTypeId = personEntityTypeId, EntityId = attendeeAttendance.PersonAlias.PersonId, RelatedEntityTypeId = locationEntityTypeId, RelatedEntityId = location.Id, Verb = "Exit", Summary = summary, Caption = "Exited Location", RelatedData = GetHostInfo(), CategoryId = 4 }; historyService.Add(history); AttendanceCache.RemoveWithParent(attendeeAttendance.PersonAlias.PersonId); }
public static void AddExitHistory(RockContext rockContext, Location location, Attendance attendeeAttendance, bool isSubroom) { var summary = string.Format("{0}</span> at <span class=\"field-name\">{1}", location.Name, Rock.RockDateTime.Now); if (isSubroom) { summary += string.Format("</span> (a subroom of <span class=\"field-name\">{0})", location.ParentLocation.Name); } var changes = new History.HistoryChangeList(); changes.AddCustom("Exit", History.HistoryChangeType.Record.ToString(), summary.Truncate(250)); changes.First().Caption = "Exited Location"; changes.First().RelatedEntityTypeId = locationEntityTypeId; changes.First().RelatedEntityId = location.Id; changes.First().RelatedData = GetHostInfo(); HistoryService.SaveChanges( rockContext, typeof(Rock.Model.Person), CategoryCache.Get(4).Guid, attendeeAttendance.PersonAlias.PersonId, changes, true ); AttendanceCache.RemoveWithParent(attendeeAttendance.PersonAlias.PersonId); }
private void ShowCheckinCompletion() { pnlQr.Visible = false; pnlPostCheckin.Visible = true; ltPostCheckin.Text = GetAttributeValue(AttributeKeys.PostCheckinInstructions); //This is all an elaborate effort to get the family's checkin data in an organized fashion without touching the db //The thought is I can add more webservers I can't add more database servers right now. var personIds = CurrentPerson.PrimaryFamily.Members.Select(m => m.Person) .OrderBy(p => p.AgeClassification) .ThenBy(p => p.BirthDate) .Select(p => p.Id) .ToList(); var attendances = AttendanceCache.All() .Where(a => personIds.Contains(a.PersonId) && a.AttendanceState != AttendanceState.CheckedOut) .ToList(); var scheduleIds = attendances.Select(a => a.ScheduleId).Distinct().ToList(); var tokenOccurrences = OccurrenceCache.All() //Just need the schedule data so we can order stuff. .Where(o => scheduleIds.Contains(o.ScheduleId)) .DistinctBy(o => o.ScheduleId) .OrderBy(o => o.ScheduleStartTime) .ToList(); var attendanceData = new StringBuilder(); foreach (var tokenOccurrence in tokenOccurrences) { if (attendances.Where(a => a.ScheduleId == tokenOccurrence.ScheduleId).Any()) { attendanceData.Append("<b>" + tokenOccurrence.ScheduleName + "</b><ul>"); foreach (var personId in personIds) { var attendance = attendances.FirstOrDefault(a => a.PersonId == personId && a.ScheduleId == tokenOccurrence.ScheduleId); if (attendance == null) { continue; } OccurrenceCache occurrence = OccurrenceCache.Get(attendance.OccurrenceAccessKey); if (occurrence == null) { continue; } attendanceData.Append(string.Format("<li>{0}: {1} in {2}</li>", attendance.PersonName, occurrence.GroupName, occurrence.LocationName)); } attendanceData.Append("</ul>"); } } ltAttendance.Text = attendanceData.ToString(); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(RockContext rockContext, WorkflowAction action, object entity, out List <string> errorMessages) { var filterAttendanceSchedules = GetActionAttributeValue(action, "FilterAttendanceSchedules").AsBoolean(); var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null) { var family = checkInState.CheckIn.Families.Where(f => f.Selected).FirstOrDefault(); if (family != null) { foreach (var person in family.People) { var inScheduleIds = AttendanceCache.All() .Where(a => a.PersonId == person.Person.Id && a.AttendanceState != AttendanceState.CheckedOut) .Select(a => a.ScheduleId) .ToList(); foreach (var groupType in person.GroupTypes) { foreach (var group in groupType.Groups) { foreach (var location in group.Locations) { foreach (var schedule in location.Schedules.ToList()) { if (filterAttendanceSchedules && inScheduleIds.Contains(schedule.Schedule.Id)) { location.Schedules.Remove(schedule); continue; } var occurrence = OccurrenceCache.Get(group.Group.Id, location.Location.Id, schedule.Schedule.Id); if (occurrence == null || occurrence.IsFull) { location.Schedules.Remove(schedule); continue; } } } } } } return(true); } else { errorMessages.Add("There is not a family that is selected"); } return(false); } errorMessages.Add($"Attempted to run {this.GetType().GetFriendlyTypeName()} in check-in, but the check-in state was null."); return(false); }
private void UpdateView() { pnlQr.Visible = false; pnlLoading.Visible = false; pnlPostCheckin.Visible = false; pnlSelectCampus.Visible = false; if (currentUser == null) { ltError.Text = GetAttributeValue(AttributeKeys.NotLoggedInMessage); pnlError.Visible = true; return; } string kioskName = currentUser.UserName; var mobileCheckinRecord = MobileCheckinRecordCache.GetActiveByFamilyGroupId(currentPerson.PrimaryFamilyId ?? 0); if (mobileCheckinRecord == null) { mobileCheckinRecord = MobileCheckinRecordCache.GetActiveByUserName(kioskName); } if (mobileCheckinRecord != null) { ShowQRCode(mobileCheckinRecord); return; } else { var completeMobileCheckins = MobileCheckinRecordCache.All() .Where(r => r.FamilyGroupId == currentPerson.PrimaryFamilyId && r.Status == MobileCheckinStatus.Complete) .SelectMany(r => r.AttendanceIds) .Select(i => AttendanceCache.Get(i)) .Where(a => a.AttendanceState != AttendanceState.CheckedOut) .Any(); if (completeMobileCheckins) { ShowCheckinCompletion(); return; } } ConfigureForUser(kioskName); pnlSelectCampus.Visible = true; }
/// <summary> /// Executes the specified context. /// </summary> /// <param name="context">The context.</param> public void Execute(IJobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; var rockContext = new RockContext(); var definedTypeService = new DefinedTypeService(rockContext); var definedValueService = new DefinedValueService(rockContext); var dtDeactivated = definedTypeService.Get(Constants.DEFINED_TYPE_DISABLED_GROUPLOCATIONSCHEDULES.AsGuid()); var dvDeactivated = dtDeactivated.DefinedValues.ToList(); var scheduleService = new ScheduleService(rockContext); var groupLocationService = new GroupLocationService(rockContext); var deactivatedGroupLocationSchedules = dvDeactivated.Select(dv => dv.Value.Split('|')) .Select(s => new { GroupLocation = groupLocationService.Get(s[0].AsInteger()), Schedule = scheduleService.Get(s[1].AsInteger()), }).ToList(); //add schedules back foreach (var groupLocationSchedule in deactivatedGroupLocationSchedules) { if (!groupLocationSchedule.GroupLocation.Schedules.Contains(groupLocationSchedule.Schedule)) { groupLocationSchedule.GroupLocation.Schedules.Add(groupLocationSchedule.Schedule); } } //Remove defined values foreach (var value in dvDeactivated) { definedValueService.Delete(value); Rock.Web.Cache.DefinedValueCache.Remove(value.Id); } //clear defined type cache Rock.Web.Cache.DefinedTypeCache.Remove(dtDeactivated.Id); rockContext.SaveChanges(); //clear caches KioskTypeCache.Clear(); Rock.CheckIn.KioskDevice.Clear(); OccurrenceCache.Clear(); AttendanceCache.Clear(); context.Result = string.Format("Finished at {0}. Reset {1} GroupScheduleLocations.", Rock.RockDateTime.Now, deactivatedGroupLocationSchedules.Count); }
private void VerifyCache() { List <string> errors = new List <string>(); KioskTypeCache.Verify(ref errors); AttendanceCache.Verify(ref errors); MobileCheckinRecordCache.Verify(ref errors); if (errors.Any()) { ltVerify.Text = string.Join("<br>", errors); } else { ltVerify.Text = "<b>No Errors</b>"; } }
public static void AddWithParentHistory(RockContext rockContext, Person person) { HistoryService historyService = new HistoryService(rockContext); var summary = string.Format("Moved to be with Parent at <span class=\"field-name\">{0}</span>", Rock.RockDateTime.Now); History history = new History() { EntityTypeId = personEntityTypeId, EntityId = person.Id, Verb = "Moved", Summary = summary, Caption = "Moved be with Parent", RelatedData = GetHostInfo(), CategoryId = 4 }; historyService.Add(history); AttendanceCache.SetWithParent(person.Id); }
public static void CloneAttendance(Attendance attendance, bool isSubroom, Location location, AttendanceService notUsed, Request req) { RockContext rockContext = new RockContext(); AttendanceService attendanceService = new AttendanceService(rockContext); Attendance newAttendance; if (!isSubroom) { newAttendance = attendanceService.AddOrUpdate(attendance.PersonAliasId, attendance.StartDateTime.Date, attendance.Occurrence.GroupId, location.Id, attendance.Occurrence.ScheduleId, location.CampusId, null, null, null, null, null, null); } else { newAttendance = attendanceService.AddOrUpdate(attendance.PersonAliasId, attendance.StartDateTime.Date, attendance.Occurrence.GroupId, location.ParentLocationId, attendance.Occurrence.ScheduleId, location.CampusId, null, null, null, null, null, null); } newAttendance.StartDateTime = Rock.RockDateTime.Now; newAttendance.EndDateTime = null; newAttendance.DidAttend = true; newAttendance.AttendanceCodeId = attendance.AttendanceCodeId; if (isSubroom) { newAttendance.ForeignId = location.Id; } else { newAttendance.ForeignId = null; } attendanceService.Add(newAttendance); var stayedFifteenMinutes = (Rock.RockDateTime.Now - attendance.StartDateTime) > new TimeSpan(0, 15, 0); attendance.DidAttend = stayedFifteenMinutes; attendance.EndDateTime = Rock.RockDateTime.Now; rockContext.SaveChanges(); AttendanceCache.RemoveWithParent(attendance.PersonAlias.PersonId); AttendanceCache.AddOrUpdate(newAttendance); AttendanceCache.AddOrUpdate(attendance); }
public static void CloseActiveAttendances(RockContext rockContext, Attendance attendeeAttendance, Location location, bool isSubroom) { var activeAttendances = ValidationHelper.GetActiveAttendances(rockContext, attendeeAttendance, location); bool didRemove = false; foreach (var activeAttendance in activeAttendances) { didRemove = true; var stayedFifteenMinutes = (Rock.RockDateTime.Now - activeAttendance.StartDateTime) > new TimeSpan(0, 15, 0); activeAttendance.DidAttend = stayedFifteenMinutes; activeAttendance.EndDateTime = Rock.RockDateTime.Now; AddExitHistory(rockContext, attendeeAttendance.Occurrence.Location, attendeeAttendance, isSubroom); AttendanceCache.AddOrUpdate(activeAttendance); } if (didRemove) { var personId = attendeeAttendance.PersonAlias.PersonId; AttendanceCache.RemoveWithParent(personId); } }
public static void AddWithParentHistory(RockContext rockContext, Person person) { var summary = string.Format("</span> to be with Parent at <span class=\"field-name\">{0}", Rock.RockDateTime.Now); var changes = new History.HistoryChangeList(); changes.AddCustom("Moved", History.HistoryChangeType.Record.ToString(), summary.Truncate(250)); changes.First().Caption = "Moved be with Parent"; changes.First().RelatedData = GetHostInfo(); HistoryService.SaveChanges( rockContext, typeof(Rock.Model.Person), CategoryCache.Get(4).Guid, person.Id, changes, true ); AttendanceCache.SetWithParent(person.Id); }
private void ShowAttendances(List <int> attendanceIds) { btnOccurrences.CssClass = defaultCss; btnAttendances.CssClass = activeCss; btnMobileRecords.CssClass = defaultCss; btnKioskTypes.CssClass = defaultCss; pnlOccurrences.Visible = false; pnlAttendances.Visible = true; pnlMobileRecords.Visible = false; pnlKioskTypes.Visible = false; pnlVerify.Visible = false; var attendances = AttendanceCache.All(); if (attendanceIds != null) { attendances = attendances.Where(a => attendanceIds.Contains(a.Id)).ToList(); } gAttendances.DataSource = attendances; gAttendances.DataBind(); }
public static void AddReturnToRoomHistory(RockContext rockContext, Person person) { HistoryService historyService = new HistoryService(rockContext); if (AttendanceCache.IsWithParent(person.Id)) { AttendanceCache.RemoveWithParent(person.Id); var summary = string.Format("Returned from Parent at <span class=\"field-name\">{0}</span>", Rock.RockDateTime.Now); History history = new History() { EntityTypeId = personEntityTypeId, EntityId = person.Id, Verb = "Returned", Summary = summary, Caption = "Returned from Parent", RelatedData = GetHostInfo(), CategoryId = 4 }; historyService.Add(history); } }
private void MobileCheckin(string accessKey) { var mobileDidAttendId = DefinedValueCache.Get(Constants.DEFINED_VALUE_MOBILE_DID_ATTEND).Id; var mobileNotAttendId = DefinedValueCache.Get(Constants.DEFINED_VALUE_MOBILE_NOT_ATTEND).Id; RockContext rockContext = new RockContext(); MobileCheckinRecordService mobileCheckinRecordService = new MobileCheckinRecordService(rockContext); var mobileCheckinRecord = mobileCheckinRecordService.Queryable().Where(r => r.AccessKey == accessKey).FirstOrDefault(); if (mobileCheckinRecord == null) { mdAlert.Show("Mobile check-in record not found", ModalAlertType.Alert); BindRepeater(); return; } else if (mobileCheckinRecord.Status == MobileCheckinStatus.Canceled) { mdAlert.Show("Mobile check-in record is expired.", ModalAlertType.Alert); BindRepeater(); return; } else if (mobileCheckinRecord.Status == MobileCheckinStatus.Complete) { mdAlert.Show("Mobile check-in record has already been completed.", ModalAlertType.Alert); BindRepeater(); return; } try { if (mobileCheckinRecord == null) { return; } List <CheckInLabel> labels = null; if (mobileCheckinRecord.Attendances.Any(a => a.EndDateTime != null)) { var people = mobileCheckinRecord.Attendances.Select(a => a.PersonAlias.Person).DistinctBy(p => p.Id).ToList(); labels = CheckinLabelGen.GenerateLabels(people, CurrentCheckInState.Kiosk.Device, GetAttributeValue("AggregatedLabel").AsGuidOrNull()); } else { labels = JsonConvert.DeserializeObject <List <CheckInLabel> >(mobileCheckinRecord.SerializedCheckInState); } LabelPrinter labelPrinter = new LabelPrinter() { Request = Request, Labels = labels }; labelPrinter.PrintNetworkLabels(); var script = labelPrinter.GetClientScript(); ScriptManager.RegisterStartupScript(upContent, upContent.GetType(), "addLabelScript", script, true); foreach (var attendance in mobileCheckinRecord.Attendances) { if (attendance.QualifierValueId == mobileDidAttendId) { attendance.DidAttend = true; attendance.QualifierValueId = null; attendance.StartDateTime = Rock.RockDateTime.Now; } else if (attendance.QualifierValueId == mobileNotAttendId) { attendance.DidAttend = false; attendance.QualifierValueId = null; } attendance.Note = "Completed mobile check-in at: " + CurrentCheckInState.Kiosk.Device.Name; } mobileCheckinRecord.Status = MobileCheckinStatus.Complete; rockContext.SaveChanges(); //wait until we successfully save to update cache foreach (var attendance in mobileCheckinRecord.Attendances) { AttendanceCache.AddOrUpdate(attendance); } MobileCheckinRecordCache.Update(mobileCheckinRecord.Id); BindRepeater(); } catch (Exception e) { LogException(e); mdAlert.Show("An unexpected issue occurred.", ModalAlertType.Alert); BindRepeater(); } }
private static List <CheckInLabel> GenerateAggregateLabel(Guid aggregateLabelGuid, Device kioskDevice, List <Person> people) { List <CheckInLabel> labels = new List <CheckInLabel>(); List <string> labelCodes = new List <string>(); foreach (var person in people) { var applicableAttendances = AttendanceCache.All().Where(p => p.PersonId == person.Id); //only if they are checked in to somewhere that is not a volunteer if (applicableAttendances.Any(a => !a.IsVolunteer)) { var newestAttendance = applicableAttendances.OrderByDescending(a => a.CreatedDateTime).FirstOrDefault(); labelCodes.Add($"{newestAttendance.Code}-{person.FormatAge()}"); } } var labelCache = KioskLabel.Get(aggregateLabelGuid); List <string> mergeCodes = labelCache.MergeFields.Keys.ToList().Where(s => Regex.IsMatch(s, "\\b[A-Z]{3}\\b")).ToList(); while (labelCodes.Count > 0 && mergeCodes.Any()) { var mergeDict = new Dictionary <string, string>(); foreach (var mergeCode in mergeCodes) { if (labelCodes.Count > 0) { mergeDict.Add(mergeCode, labelCodes[0]); labelCodes.RemoveAt(0); } else { mergeDict.Add(mergeCode, ""); } } mergeDict.Add("Date", Rock.RockDateTime.Today.DayOfWeek.ToString().Substring(0, 3) + " " + Rock.RockDateTime.Today.ToMonthDayString()); if (labelCache != null) { var checkInLabel = new CheckInLabel(labelCache, new Dictionary <string, object>()); checkInLabel.FileGuid = aggregateLabelGuid; foreach (var keyValue in mergeDict) { if (checkInLabel.MergeFields.ContainsKey(keyValue.Key)) { checkInLabel.MergeFields[keyValue.Key] = keyValue.Value; } else { checkInLabel.MergeFields.Add(keyValue.Key, keyValue.Value); } } checkInLabel.PrintFrom = kioskDevice.PrintFrom; checkInLabel.PrintTo = kioskDevice.PrintToOverride; if (checkInLabel.PrintTo == PrintTo.Kiosk) { var device = kioskDevice; if (device != null) { checkInLabel.PrinterDeviceId = device.PrinterDeviceId; } } if (checkInLabel.PrinterDeviceId.HasValue) { var printerDevice = new DeviceService(new RockContext()).Get(checkInLabel.PrinterDeviceId.Value); checkInLabel.PrinterAddress = printerDevice.IPAddress; } labels.Add(checkInLabel); } } return(labels); }
public static List <CheckInLabel> GenerateLabels(List <Person> people, Device kioskDevice, Guid?aggregateLabelGuid) { var labels = new List <CheckInLabel>(); var globalAttributes = Rock.Web.Cache.GlobalAttributesCache.Get(); var globalMergeValues = Rock.Lava.LavaHelper.GetCommonMergeFields(null); RockContext rockContext = new RockContext(); AttendanceService attendanceService = new AttendanceService(rockContext); foreach (var person in people) { var attendances = AttendanceCache.All() .Where(a => a.PersonId == person.Id && a.AttendanceState != AttendanceState.CheckedOut) .ToList(); if (!attendances.Any()) { continue; } var groupIds = attendances.Select(a => a.GroupId).Distinct().ToList(); GroupService groupService = new GroupService(new RockContext()); var groupTypeIds = groupService.Queryable() .Where(g => groupIds.Contains(g.Id)) .Select(g => g.GroupTypeId) .Distinct() .ToList(); var groupTypes = groupTypeIds .Select(i => GroupTypeCache.Get(i)) .OrderBy(gt => gt.Order) .ToList(); List <Guid> labelGuids = new List <Guid>(); var mergeObjects = new Dictionary <string, object>(); foreach (var keyValue in globalMergeValues) { mergeObjects.Add(keyValue.Key, keyValue.Value); } var checkinPerson = new CheckInPerson { Person = person, SecurityCode = attendances.OrderByDescending(a => a.CreatedDateTime).FirstOrDefault().Code }; mergeObjects.Add("Person", checkinPerson); mergeObjects.Add("GroupTypes", groupTypes); List <Rock.Model.Group> mergeGroups = new List <Rock.Model.Group>(); List <Location> mergeLocations = new List <Location>(); List <Schedule> mergeSchedules = new List <Schedule>(); var sets = attendanceService .Queryable().AsNoTracking().Where(a => a.PersonAlias.Person.Id == person.Id && a.StartDateTime >= Rock.RockDateTime.Today && a.EndDateTime == null && a.Occurrence.Group != null && a.Occurrence.Schedule != null && a.Occurrence.Location != null ) .Select(a => new { Group = a.Occurrence.Group, Location = a.Occurrence.Location, Schedule = a.Occurrence.Schedule, AttendanceGuid = a.Guid } ) .ToList() .OrderBy(a => a.Schedule.StartTimeOfDay); //Load breakout group var breakoutGroups = GetBreakoutGroups(person, rockContext); //Add in an empty object as a placeholder for our breakout group mergeObjects.Add("BreakoutGroup", ""); //Add in GUID for QR code if (sets.Any()) { mergeObjects.Add("AttendanceGuid", sets.FirstOrDefault().AttendanceGuid.ToString()); } foreach (var set in sets) { mergeGroups.Add(set.Group); mergeLocations.Add(set.Location); mergeSchedules.Add(set.Schedule); //Add the breakout group mergefield if (breakoutGroups.Any()) { var breakoutGroup = breakoutGroups.Where(g => g.ScheduleId == set.Schedule.Id).FirstOrDefault(); if (breakoutGroup != null) { var breakoutGroupEntity = new GroupService(rockContext).Get(breakoutGroup.Id); if (breakoutGroupEntity != null) { breakoutGroupEntity.LoadAttributes(); var letter = breakoutGroupEntity.GetAttributeValue("Letter"); if (!string.IsNullOrWhiteSpace(letter)) { mergeObjects["BreakoutGroup"] = letter; } } } } } mergeObjects.Add("Groups", mergeGroups); mergeObjects.Add("Locations", mergeLocations); mergeObjects.Add("Schedules", mergeSchedules); foreach (var groupType in groupTypes) { var groupTypeLabels = new List <CheckInLabel>(); GetGroupTypeLabels(groupType, groupTypeLabels, mergeObjects, labelGuids); var PrinterIPs = new Dictionary <int, string>(); foreach (var label in groupTypeLabels) { label.PrintFrom = kioskDevice.PrintFrom; label.PrintTo = kioskDevice.PrintToOverride; if (label.PrintTo == PrintTo.Default) { label.PrintTo = groupType.AttendancePrintTo; } if (label.PrintTo == PrintTo.Kiosk) { var device = kioskDevice; if (device != null) { label.PrinterDeviceId = device.PrinterDeviceId; } } if (label.PrinterDeviceId.HasValue) { if (PrinterIPs.ContainsKey(label.PrinterDeviceId.Value)) { label.PrinterAddress = PrinterIPs[label.PrinterDeviceId.Value]; } else { var printerDevice = new DeviceService(rockContext).Get(label.PrinterDeviceId.Value); if (printerDevice != null) { PrinterIPs.Add(printerDevice.Id, printerDevice.IPAddress); label.PrinterAddress = printerDevice.IPAddress; } } } labels.Add(label); } } } if (aggregateLabelGuid.HasValue) { labels.AddRange(GenerateAggregateLabel(aggregateLabelGuid.Value, kioskDevice, people)); } return(labels); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(RockContext rockContext, Rock.Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var isMobile = GetAttributeValue(action, "IsMobile").AsBoolean(); var mobileDidAttendId = DefinedValueCache.Get(Constants.DEFINED_VALUE_MOBILE_DID_ATTEND).Id; var mobileNotAttendId = DefinedValueCache.Get(Constants.DEFINED_VALUE_MOBILE_NOT_ATTEND).Id; var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null) { KioskService kioskService = new KioskService(rockContext); var kioskTypeId = kioskService.GetByClientName(checkInState.Kiosk.Device.Name).KioskTypeId; var kioskType = KioskTypeCache.Get(kioskTypeId.Value); var campusId = kioskType.CampusId; if (campusId == null) { var compatableKioskType = KioskTypeCache.All().Where(kt => kt.CampusId.HasValue && kt.CheckinTemplateId == kioskType.CheckinTemplateId).FirstOrDefault(); if (compatableKioskType != null) { campusId = compatableKioskType.CampusId; } else { campusId = 0; } } campusId = GetCampusOrFamilyCampusId(campusId, checkInState.CheckIn.CurrentFamily.Group.CampusId); AttendanceCode attendanceCode = null; DateTime startDateTime = Rock.RockDateTime.Now; DateTime today = startDateTime.Date; DateTime tomorrow = startDateTime.AddDays(1); bool reuseCodeForFamily = checkInState.CheckInType != null && checkInState.CheckInType.ReuseSameCode; int securityCodeLength = checkInState.CheckInType != null ? checkInState.CheckInType.SecurityCodeAlphaNumericLength : 3; var attendanceCodeService = new AttendanceCodeService(rockContext); var attendanceService = new AttendanceService(rockContext); var groupMemberService = new GroupMemberService(rockContext); var personAliasService = new PersonAliasService(rockContext); //This list is just for mobile check-in List <Attendance> attendances = new List <Attendance>(); var family = checkInState.CheckIn.CurrentFamily; if (family != null) { foreach (var person in family.GetPeople(true)) { if (reuseCodeForFamily && attendanceCode != null) { person.SecurityCode = attendanceCode.Code; } else { attendanceCode = AttendanceCodeService.GetNew(securityCodeLength); person.SecurityCode = attendanceCode.Code; } foreach (var groupType in person.GetGroupTypes(true)) { foreach (var group in groupType.GetGroups(true)) { if (groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn && groupType.GroupType.DefaultGroupRoleId.HasValue && !groupMemberService.GetByGroupIdAndPersonId(group.Group.Id, person.Person.Id, true).Any()) { var groupMember = new GroupMember(); groupMember.GroupId = group.Group.Id; groupMember.PersonId = person.Person.Id; groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value; groupMemberService.Add(groupMember); } foreach (var location in group.GetLocations(true)) { foreach (var schedule in location.GetSchedules(true)) { var primaryAlias = personAliasService.GetPrimaryAlias(person.Person.Id); if (primaryAlias != null) { int groupId = ActualGroupId(group.Group); // If a like attendance service exists close it before creating another one. var oldAttendance = attendanceService.Queryable() .Where(a => a.StartDateTime >= today && a.StartDateTime < tomorrow && a.Occurrence.LocationId == location.Location.Id && a.Occurrence.ScheduleId == schedule.Schedule.Id && a.Occurrence.GroupId == groupId && a.PersonAlias.PersonId == person.Person.Id) .FirstOrDefault(); if (oldAttendance != null) { oldAttendance.EndDateTime = Rock.RockDateTime.Now; oldAttendance.DidAttend = false; } var attendance = attendanceService.AddOrUpdate(primaryAlias.Id, startDateTime.Date, groupId, location.Location.Id, schedule.Schedule.Id, campusId ?? location.CampusId, checkInState.Kiosk.Device.Id, checkInState.CheckIn.SearchType.Id, checkInState.CheckIn.SearchValue, family.Group.Id, attendanceCode.Id); attendance.DeviceId = checkInState.Kiosk.Device.Id; attendance.SearchTypeValueId = checkInState.CheckIn.SearchType.Id; attendance.SearchValue = checkInState.CheckIn.SearchValue; attendance.CheckedInByPersonAliasId = checkInState.CheckIn.CheckedInByPersonAliasId; attendance.SearchResultGroupId = family.Group.Id; attendance.AttendanceCodeId = attendanceCode.Id; attendance.CreatedDateTime = startDateTime; attendance.StartDateTime = startDateTime; attendance.EndDateTime = null; attendance.Note = group.Notes; attendance.DidAttend = isMobile ? false : groupType.GroupType.GetAttributeValue("SetDidAttend").AsBoolean(); if (isMobile) { if (groupType.GroupType.GetAttributeValue("SetDidAttend").AsBoolean()) { attendance.QualifierValueId = mobileDidAttendId; } else { attendance.QualifierValueId = mobileNotAttendId; } } ; attendanceService.Add(attendance); attendances.Add(attendance); } } } } } } } if (isMobile) { var alreadyExistingMobileCheckin = MobileCheckinRecordCache.GetActiveByFamilyGroupId(checkInState.CheckIn.CurrentFamily.Group.Id); if (alreadyExistingMobileCheckin != null) { //This should never run, it's just in case. Each family should only have 1 mobile check-in reservation. MobileCheckinRecordCache.CancelReservation(alreadyExistingMobileCheckin, true); } campusId = RollUpToParentCampus(campusId); MobileCheckinRecordService mobileCheckinRecordService = new MobileCheckinRecordService(rockContext); var mobileCheckinRecord = new MobileCheckinRecord { AccessKey = "MCR" + Guid.NewGuid().ToString("N").Substring(0, 12), ReservedUntilDateTime = Rock.RockDateTime.Now.AddMinutes(kioskType.MinutesValid ?? 10), ExpirationDateTime = Rock.RockDateTime.Now.AddMinutes((kioskType.MinutesValid ?? 10) + (kioskType.GraceMinutes ?? 60)), UserName = checkInState.CheckIn.SearchValue, FamilyGroupId = checkInState.CheckIn.CurrentFamily.Group.Id, CampusId = campusId.Value }; foreach (var attendance in attendances) { mobileCheckinRecord.Attendances.Add(attendance); } mobileCheckinRecordService.Add(mobileCheckinRecord); } rockContext.SaveChanges(); foreach (var attendance in attendances) { AttendanceCache.AddOrUpdate(attendance); } return(true); } errorMessages.Add($"Attempted to run {this.GetType().GetFriendlyTypeName()} in check-in, but the check-in state was null."); return(false); }
private void MobileCheckin(string accessKey) { var mobileDidAttendId = DefinedValueCache.Get(Constants.DEFINED_VALUE_MOBILE_DID_ATTEND).Id; var mobileNotAttendId = DefinedValueCache.Get(Constants.DEFINED_VALUE_MOBILE_NOT_ATTEND).Id; RockContext rockContext = new RockContext(); MobileCheckinRecordService mobileCheckinRecordService = new MobileCheckinRecordService(rockContext); var mobileCheckinRecord = mobileCheckinRecordService.Queryable().Where(r => r.AccessKey == accessKey).FirstOrDefault(); if (mobileCheckinRecord == null) { MobileCheckinMessage(GetAttributeValue(AttributeKeys.NoMobileCheckinRecord)); return; } else if (mobileCheckinRecord.Status == MobileCheckinStatus.Canceled) { MobileCheckinMessage(GetAttributeValue(AttributeKeys.ExpiredMobileCheckinRecord)); return; } else if (mobileCheckinRecord.Status == MobileCheckinStatus.Complete) { MobileCheckinMessage(GetAttributeValue(AttributeKeys.AlreadyCompleteCheckinRecord)); return; } try { if (mobileCheckinRecord == null) { return; } if (KioskType.CampusId.HasValue && KioskType.CampusId != 0 && KioskType.CampusId != mobileCheckinRecord.CampusId) { ShowWrongCampusSign(mobileCheckinRecord.Campus.Name, KioskType.Campus.Name); return; } List <CheckInLabel> labels = JsonConvert.DeserializeObject <List <CheckInLabel> >(mobileCheckinRecord.SerializedCheckInState); LabelPrinter labelPrinter = new LabelPrinter() { Request = Request, Labels = labels }; labelPrinter.PrintNetworkLabels(); var script = labelPrinter.GetClientScript(); ScriptManager.RegisterStartupScript(upContent, upContent.GetType(), "addLabelScript", script, true); foreach (var attendance in mobileCheckinRecord.Attendances) { if (attendance.QualifierValueId == mobileDidAttendId) { attendance.DidAttend = true; attendance.QualifierValueId = null; attendance.StartDateTime = Rock.RockDateTime.Now; } else if (attendance.QualifierValueId == mobileNotAttendId) { attendance.DidAttend = false; attendance.QualifierValueId = null; } attendance.Note = "Completed mobile check-in at: " + CurrentCheckInState.Kiosk.Device.Name; } mobileCheckinRecord.Status = MobileCheckinStatus.Complete; rockContext.SaveChanges(); //wait until we successfully save to update cache foreach (var attendance in mobileCheckinRecord.Attendances) { AttendanceCache.AddOrUpdate(attendance); } MobileCheckinRecordCache.Update(mobileCheckinRecord.Id); MobileCheckinMessage(GetAttributeValue(AttributeKeys.CompletingMobileCheckin), 5); } catch (Exception e) { } }
protected void btnFlushAttendance_Click(object sender, EventArgs e) { AttendanceCache.Clear(); AttendanceCache.All(); }