/// <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 checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null) { var people = checkInState.CheckIn.CurrentFamily.People .Where(p => p.Selected) .Select(p => p.Person) .ToList(); var checkInLabels = CheckinLabelGen.GenerateLabels(people, checkInState.Kiosk.Device, GetAttributeValue(action, "AggregatedLabel").AsGuidOrNull()); var groupType = checkInState.CheckIn.CurrentFamily.People .Where(p => p.Selected) .SelectMany(p => p.GroupTypes.Where(gt => gt.Selected)) .FirstOrDefault(); if (groupType != null) { groupType.Labels = checkInLabels; } //For mobile check-in we need to serialize this data and save it in the database. //This will mean that when it's time to finish checkin in //All we will need to do is deserialize and pass the data to the printer if (GetAttributeValue(action, "IsMobile").AsBoolean()) { MobileCheckinRecordService mobileCheckinRecordService = new MobileCheckinRecordService(rockContext); MobileCheckinRecord mobileCheckinRecord = mobileCheckinRecordService.Queryable() .Where(r => r.Status == MobileCheckinStatus.Active) .Where(r => r.CreatedDateTime > Rock.RockDateTime.Today) .Where(r => r.UserName == checkInState.CheckIn.SearchValue) .FirstOrDefault(); if (mobileCheckinRecord == null) { ExceptionLogService.LogException("Mobile Check-in failed to find mobile checkin record"); } mobileCheckinRecord.SerializedCheckInState = JsonConvert.SerializeObject(checkInLabels); rockContext.SaveChanges(); //Freshen cache (we're going to need it soon) MobileCheckinRecordCache.Update(mobileCheckinRecord.Id); } 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) { 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(); } }