/// <summary> Saves the family's label set as AttendanceData to the attendance records /// associated with the current check-in (using the given attendanceIds). The label /// data looks like: /// <![CDATA[ /// [ /// { /// "LabelType":0, /// "Order":0, /// "PersonId":4, /// "PrinterDeviceId":1, /// "PrinterAddress":"10.1.20.200", /// "PrintFrom":0, /// "PrintTo":1, /// "FileGuid":"9b098db0-952c-43fb-a5bd-511e3c2b72fb", /// "LabelFile":"/GetFile.ashx?id=33", /// "LabelKey":"9b098db0-952c-43fb-a5bd-511e3c2b72fb", /// "MergeFields":{ /// "WWW":"K46", /// "2":"Ted Decker", /// "AAA":"", /// "3":"Bears Room 4:30 (test)", /// "LLL":"", /// "5":"", /// "7":"" /// } /// }, /// { /// "LabelType":1, /// ... /// }, /// ... /// ] /// ]]> /// </summary> /// <param name="family">A CheckInFamily that holds the labels to be stored.</param> private void SaveLabelToAttendance(CheckInFamily family) { if (family == null || family.People == null) { return; } var labels = family.People.SelectMany(p => p.GroupTypes).Where(gt => gt.Labels != null).SelectMany(gt => gt.Labels).ToList(); if (labels == null || labels.Count == 0) { return; } var rockContext = new RockContext(); var attendanceRecords = new AttendanceService(rockContext).Queryable().Where(a => family.AttendanceIds.Contains(a.Id)); var labelData = JsonConvert.SerializeObject(labels); foreach (var attendance in attendanceRecords) { if (attendance.AttendanceData == null) { attendance.AttendanceData = new AttendanceData(); } attendance.AttendanceData.LabelData = labelData; } rockContext.SaveChanges(); }
/// <summary> /// Processes for family. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="family">The family.</param> /// <param name="preventInactivePeople">if set to <c>true</c> [prevent inactive people]. Usually get from CurrentCheckInState.CheckInType.PreventInactivePeople</param> /// <returns></returns> public static bool ProcessForFamily(RockContext rockContext, CheckInFamily family, bool preventInactivePeople) { var service = new GroupMemberService(rockContext); var people = service.GetByGroupId(family.Group.Id).AsNoTracking(); if (preventInactivePeople) { var dvInactive = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid()); if (dvInactive != null) { people = people.Where(m => m.Person.RecordStatusValueId != dvInactive.Id); } } foreach (var groupMember in people.ToList()) { if (!family.People.Any(p => p.Person.Id == groupMember.PersonId)) { var person = new CheckInPerson(); person.Person = groupMember.Person.Clone(false); person.FamilyMember = true; family.People.Add(person); } } return(true); }
/// <summary> /// Refreshes the family. /// </summary> private void ProcessFamily(CheckInFamily selectedFamily = null) { selectedFamily = selectedFamily ?? CurrentCheckInState.CheckIn.Families.FirstOrDefault(f => f.Selected); var familyList = CurrentCheckInState.CheckIn.Families .OrderByDescending(f => f.Group.CampusId == KioskCampusId) .ThenBy(f => f.Caption).Take(50).ToList(); // Order families by campus then by caption if (CurrentCheckInState.CheckIn.Families.Count > 1) { dpFamilyPager.Visible = true; dpFamilyPager.SetPageProperties(0, dpFamilyPager.MaximumRows, false); } if (selectedFamily != null) { selectedFamily.Selected = true; } else { familyList.FirstOrDefault().Selected = true; } lvFamily.DataSource = familyList; lvFamily.DataBind(); pnlFamily.Update(); }
public ActionResult Family( string data ) { if( !Auth() ) return CheckInMessage.createErrorReturn( "Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS ); CheckInMessage dataIn = CheckInMessage.createFromString( data ); CheckInFamilySearch cfs = JsonConvert.DeserializeObject<CheckInFamilySearch>( dataIn.data ); DbUtil.LogActivity( "Check-In Family: " + cfs.familyID ); CheckInMessage br = new CheckInMessage(); br.setNoError(); int tzOffset = DbUtil.Db.Setting( "TZOffset", "0" ).ToInt(); List<CheckInFamily> families = new List<CheckInFamily>(); FamilyCheckinLock familyLock = DbUtil.Db.FamilyCheckinLocks.SingleOrDefault( f => f.FamilyId == dataIn.argInt ); CheckInFamily family = new CheckInFamily( cfs.familyID, "", familyLock?.Locked ?? false ); List<CheckinFamilyMember> members = (from a in DbUtil.Db.CheckinFamilyMembers( cfs.familyID, cfs.campus, cfs.day ).ToList() orderby a.Position, a.Position == 10 ? a.Genderid : 10, a.Age descending, a.Hour select a).ToList(); foreach( CheckinFamilyMember member in members ) { family.addMember( member, cfs.day, tzOffset ); } families.Add( family ); br.count = 1; br.data = SerializeJSON( families, dataIn.version ); return br; }
/// <summary> /// Adds the visitor group member roles. /// </summary> /// <param name="family">The family.</param> /// <param name="visitorId">The person id.</param> private void AddVisitorRelationships(CheckInFamily family, int visitorId, RockContext rockContext = null) { rockContext = rockContext ?? new RockContext(); foreach (var familyMember in family.People.Where(p => p.FamilyMember && p.Person.Age >= 18)) { Person.CreateCheckinRelationship(familyMember.Person.Id, visitorId, rockContext); } }
/// <summary> /// Processes for family. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="family">The family.</param> /// <param name="preventInactive">if set to <c>true</c> [prevent inactive]. Use CurrentCheckInState.CheckInType.PreventInactivePeople</param> /// <returns></returns> public static bool ProcessForFamily(RockContext rockContext, CheckInFamily family, bool preventInactive) { var dvInactive = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid()); var roles = GetRoles(rockContext); var groupMemberService = new GroupMemberService(rockContext); var familyMemberIds = family.People.Select(p => p.Person.Id).ToList(); var knownRelationshipGroupType = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_KNOWN_RELATIONSHIPS.AsGuid()); if (knownRelationshipGroupType != null) { var ownerRole = knownRelationshipGroupType.Roles.FirstOrDefault(r => r.Guid == Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER.AsGuid()); if (ownerRole != null) { // Get the Known Relationship group id's for each person in the family var relationshipGroupIds = groupMemberService .Queryable().AsNoTracking() .Where(g => g.GroupRoleId == ownerRole.Id && familyMemberIds.Contains(g.PersonId)) .Select(g => g.GroupId); // Get anyone in any of those groups that has a role with the canCheckIn attribute set var personIds = groupMemberService .Queryable().AsNoTracking() .Where(g => relationshipGroupIds.Contains(g.GroupId) && roles.Contains(g.GroupRoleId)) .Select(g => g.PersonId) .ToList(); if (personIds.Any()) { foreach (var person in new PersonService(rockContext) .Queryable().AsNoTracking() .Where(p => personIds.Contains(p.Id)) .ToList()) { if (!family.People.Any(p => p.Person.Id == person.Id)) { if (!preventInactive || dvInactive == null || person.RecordStatusValueId != dvInactive.Id) { var relatedPerson = new CheckInPerson(); relatedPerson.Person = person.Clone(false); relatedPerson.FamilyMember = false; family.People.Add(relatedPerson); } } } } } } return(true); }
/// <summary> /// Processes the family. /// </summary> private void ProcessPeople(CheckInFamily selectedFamily = null) { var errors = new List <string>(); if (ProcessActivity("Person Search", out errors)) { List <CheckInPerson> memberDataSource = null; List <CheckInPerson> visitorDataSource = null; selectedFamily = selectedFamily ?? CurrentCheckInState.CheckIn.Families.FirstOrDefault(f => f.Selected); if (selectedFamily != null && selectedFamily.People.Any(f => !f.ExcludedByFilter)) { memberDataSource = selectedFamily.People.Where(f => f.FamilyMember && !f.ExcludedByFilter) .OrderByDescending(p => p.Person.AgePrecise).ToList(); memberDataSource.ForEach(p => p.Selected = true); hfSelectedPerson.Value = string.Join(",", memberDataSource.Select(f => f.Person.Id)) + ","; visitorDataSource = selectedFamily.People.Where(f => !f.FamilyMember && !f.ExcludedByFilter) .OrderByDescending(p => p.Person.AgePrecise).ToList(); if (visitorDataSource.Any(f => f.Selected)) { hfSelectedVisitor.Value = string.Join(",", visitorDataSource.Where(f => f.Selected) .Select(f => f.Person.Id).ToList()) + ","; } } lvPerson.DataSource = memberDataSource; lvPerson.DataBind(); lvVisitor.DataSource = visitorDataSource; lvVisitor.DataBind(); if (memberDataSource != null) { dpPersonPager.Visible = true; dpPersonPager.SetPageProperties(0, dpPersonPager.MaximumRows, false); } if (visitorDataSource != null) { dpVisitorPager.Visible = true; dpVisitorPager.SetPageProperties(0, dpVisitorPager.MaximumRows, false); } // Force an update pnlPerson.Update(); pnlVisitor.Update(); } else { string errorMsg = "<ul><li>" + errors.AsDelimited("</li><li>") + "</li></ul>"; maWarning.Show(errorMsg.Replace("'", @"\'"), ModalAlertType.Warning); } }
/// <summary> /// Handles the Click event of the lbAddSearchedForPerson 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 lbSavePerson_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbFirstNameSearch.Text) || string.IsNullOrEmpty(tbLastNameSearch.Text) || string.IsNullOrEmpty(dpDOBSearch.Text) || ddlGenderSearch.SelectedValueAsInt() == 0) { // modal takes care of the validation Page.Validate("Person"); mpeAddPerson.Show(); } else { var checkInFamily = CurrentCheckInState.CheckIn.Families.Where(f => f.Selected).FirstOrDefault(); if (checkInFamily == null) { checkInFamily = new CheckInFamily(); var familyGroup = CreateFamily(tbLastNameSearch.Text); checkInFamily.Group = familyGroup; checkInFamily.Caption = familyGroup.Name; } var checkInPerson = new CheckInPerson(); checkInPerson.Person = CreatePerson(tbFirstNameSearch.Text, tbLastNameSearch.Text, dpDOBSearch.SelectedDate, (int)ddlGenderSearch.SelectedValueAsEnum <Gender>(), ddlAbilitySearch.SelectedValue, ddlAbilitySearch.SelectedItem.Attributes["optiongroup"]); if (personVisitorType.Value != "Visitor") { // Family Member var groupMember = AddGroupMember(checkInFamily.Group.Id, checkInPerson.Person); checkInPerson.FamilyMember = true; hfSelectedPerson.Value += checkInPerson.Person.Id + ","; } else { // Visitor AddVisitorGroupMemberRoles(checkInFamily, checkInPerson.Person.Id); checkInPerson.FamilyMember = false; hfSelectedVisitor.Value += checkInPerson.Person.Id + ","; } checkInPerson.Selected = true; checkInFamily.People.Add(checkInPerson); checkInFamily.SubCaption = string.Join(",", checkInFamily.People.Select(p => p.Person.FirstName)); checkInFamily.Selected = true; CurrentCheckInState.CheckIn.Families.Add(checkInFamily); tbFirstNameSearch.Required = false; tbLastNameSearch.Required = false; ddlGenderSearch.Required = false; dpDOBSearch.Required = false; ProcessFamily(); } }
public ActionResult NumberSearch(string data) { if (!Auth()) { return(CheckInMessage.createErrorReturn("Authentication failed, please try again", CheckInMessage.API_ERROR_INVALID_CREDENTIALS)); } CheckInMessage dataIn = CheckInMessage.createFromString(data); CheckInNumberSearch cns = JsonConvert.DeserializeObject <CheckInNumberSearch>(dataIn.data); DbUtil.LogActivity("Check-In Number Search: " + cns.search); List <CheckinMatch> matches = CurrentDatabase.CheckinMatch(cns.search).ToList(); CheckInMessage br = new CheckInMessage(); br.setNoError(); int tzOffset = CurrentDatabase.Setting("TZOffset", "0").ToInt(); List <CheckInFamily> families = new List <CheckInFamily>(); if (matches.Count > 0) { foreach (CheckinMatch match in matches) { if (match.Familyid != null) { CheckInFamily family = new CheckInFamily(match.Familyid.Value, match.Name, match.Locked ?? false, CurrentDatabase, CurrentImageDatabase); List <CheckinFamilyMember> members = (from a in CurrentDatabase.CheckinFamilyMembers(match.Familyid, cns.campus, cns.day).ToList() orderby a.Position, a.Position == 10 ? a.Genderid : 10, a.Age descending, a.Hour select a).ToList(); foreach (CheckinFamilyMember member in members) { family.addMember(CurrentDatabase, CurrentImageDatabase, member, cns.day, tzOffset); } families.Add(family); br.count++; } } br.data = SerializeJSON(families, dataIn.version); } return(br); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <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(Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null) { using (new Rock.Data.UnitOfWorkScope()) { var personService = new PersonService(); var memberService = new GroupMemberService(); IQueryable <Person> people = null; if (checkInState.CheckIn.SearchType.Guid.Equals(new Guid(SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER))) { people = personService.GetByPhonePartial(checkInState.CheckIn.SearchValue); } else if (checkInState.CheckIn.SearchType.Guid.Equals(new Guid(SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_NAME))) { people = personService.GetByFullName(checkInState.CheckIn.SearchValue); } else { errorMessages.Add("Invalid Search Type"); return(false); } foreach (var person in people.ToList()) { foreach (var group in person.Members.Where(m => m.Group.GroupType.Guid == new Guid(SystemGuid.GroupType.GROUPTYPE_FAMILY)).Select(m => m.Group).ToList()) { var family = checkInState.CheckIn.Families.Where(f => f.Group.Id == group.Id).FirstOrDefault(); if (family == null) { family = new CheckInFamily(); family.Group = group.Clone(false); family.Group.LoadAttributes(); family.Caption = group.ToString(); family.SubCaption = memberService.GetFirstNames(group.Id).ToList().AsDelimited(", "); checkInState.CheckIn.Families.Add(family); } } } return(true); } } errorMessages.Add("Invalid Check-in State"); return(false); }
/// <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) { if (GetActionAttributeValue(action, "AlwaysSearch").AsBoolean() || !checkInState.CheckIn.Families.Any()) { var searchValue = checkInState.CheckIn.SearchValue.Trim(); long n; bool isNumeric = long.TryParse(searchValue, out n); if (isNumeric) { UserLoginService userLogin = new UserLoginService(rockContext); var user = userLogin.GetByUserName(searchValue); if (user != null) { //Short PINs can be confused for phone numbers. Clear families if we have selected. if (GetActionAttributeValue(action, "ClearFamilies").AsBoolean()) { checkInState.CheckIn.Families.Clear(); } var memberService = new GroupMemberService(rockContext); var families = user.Person.GetFamilies(); foreach (var group in families) { var family = checkInState.CheckIn.Families.Where(f => f.Group.Id == group.Id).FirstOrDefault(); if (family == null) { family = new CheckInFamily(); family.Group = group.Clone(false); family.Group.LoadAttributes(rockContext); family.Caption = group.ToString(); family.SubCaption = memberService.GetFirstNames(group.Id).ToList().AsDelimited(", "); checkInState.CheckIn.Families.Add(family); } } } } } return(true); } errorMessages.Add($"Attempted to run {this.GetType().GetFriendlyTypeName()} in check-in, but the check-in state was null."); return(false); }
/// <summary> /// Handles the ItemDataBound event of the rSelection control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RepeaterItemEventArgs"/> instance containing the event data.</param> protected void rSelection_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item == null) { return; } CheckInFamily checkInFamily = e.Item.DataItem as CheckInFamily; if (checkInFamily == null) { return; } Panel pnlSelectFamilyPostback = e.Item.FindControl("pnlSelectFamilyPostback") as Panel; pnlSelectFamilyPostback.Attributes["data-target"] = Page.ClientScript.GetPostBackEventReference(rSelection, checkInFamily.Group.Id.ToString()); pnlSelectFamilyPostback.Attributes["data-loading-text"] = "Loading..."; Literal lSelectFamilyButtonHtml = e.Item.FindControl("lSelectFamilyButtonHtml") as Literal; var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, null, new Rock.Lava.CommonMergeFieldsOptions { GetLegacyGlobalMergeFields = false }); mergeFields.Add("Family", checkInFamily); mergeFields.Add("Kiosk", CurrentCheckInState.Kiosk); mergeFields.Add("RegistrationModeEnabled", CurrentCheckInState.Kiosk.RegistrationModeEnabled); // prepare a query with a new context in case the Lava wants to access Members of this family, and so that lazy loading will work using (var rockContext = new Rock.Data.RockContext()) { var familyMembersQuery = new GroupMemberService(rockContext).Queryable().Include(a => a.Person).Include(a => a.GroupRole) .AsNoTracking() .Where(a => a.GroupId == checkInFamily.Group.Id) .OrderBy(m => m.GroupRole.Order) .ThenBy(m => m.Person.BirthYear) .ThenBy(m => m.Person.BirthMonth) .ThenBy(m => m.Person.BirthDay) .ThenBy(m => m.Person.Gender); var familySelectLavaTemplate = CurrentCheckInState.CheckInType.FamilySelectLavaTemplate; mergeFields.Add("FamilyMembers", familyMembersQuery); lSelectFamilyButtonHtml.Text = familySelectLavaTemplate.ResolveMergeFields(mergeFields); } }
/// <summary> /// Handles the Click event of the lbAddFamilySave 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 lbSaveFamily_Click(object sender, EventArgs e) { var newFamilyList = (List <NewPerson>)ViewState["newFamily"]; var checkInFamily = new CheckInFamily(); CheckInPerson checkInPerson; NewPerson newPerson; // add the new people foreach (ListViewItem item in lvAddFamily.Items) { newPerson = new NewPerson(); newPerson.FirstName = ((TextBox)item.FindControl("tbFirstName")).Text; newPerson.LastName = ((TextBox)item.FindControl("tbLastName")).Text; newPerson.BirthDate = ((DatePicker)item.FindControl("dpBirthDate")).SelectedDate; newPerson.Gender = ((RockDropDownList)item.FindControl("ddlGender")).SelectedValueAsEnum <Gender>(); newPerson.Ability = ((RockDropDownList)item.FindControl("ddlAbilityGrade")).SelectedValue; newPerson.AbilityGroup = ((RockDropDownList)item.FindControl("ddlAbilityGrade")).SelectedItem.Attributes["optiongroup"]; newFamilyList.Add(newPerson); } var lastName = newFamilyList.Where(p => p.BirthDate.HasValue).OrderBy(p => p.BirthDate).Select(p => p.LastName).FirstOrDefault(); var familyGroup = CreateFamily(lastName); // create people and add to checkin foreach (NewPerson np in newFamilyList.Where(np => np.IsValid())) { var person = CreatePerson(np.FirstName, np.LastName, np.BirthDate, (int)np.Gender, np.Ability, np.AbilityGroup); var groupMember = AddGroupMember(familyGroup.Id, person); familyGroup.Members.Add(groupMember); checkInPerson = new CheckInPerson(); checkInPerson.Person = person; checkInPerson.Selected = true; checkInPerson.FamilyMember = true; checkInFamily.People.Add(checkInPerson); } checkInFamily.Group = familyGroup; checkInFamily.Caption = familyGroup.Name; checkInFamily.SubCaption = string.Join(",", checkInFamily.People.Select(p => p.Person.FirstName)); checkInFamily.Selected = true; CurrentCheckInState.CheckIn.Families.Clear(); CurrentCheckInState.CheckIn.Families.Add(checkInFamily); ProcessFamily(); RefreshFamily(); }
/// <summary> /// Adds the visitor group member roles. /// </summary> /// <param name="family">The family.</param> /// <param name="personId">The person id.</param> protected void AddVisitorGroupMemberRoles(CheckInFamily family, int personId) { var rockContext = new RockContext(); var groupService = new GroupService(rockContext); var groupMemberService = new GroupMemberService(rockContext); var groupRoleService = new GroupTypeRoleService(rockContext); int ownerRoleId = groupRoleService.Get(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_OWNER)).Id; int canCheckInId = groupRoleService.Get(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_KNOWN_RELATIONSHIPS_CAN_CHECK_IN)).Id; foreach (var familyMember in family.People) { var group = groupMemberService.Queryable() .Where(m => m.PersonId == familyMember.Person.Id && m.GroupRoleId == ownerRoleId) .Select(m => m.Group) .FirstOrDefault(); if (group == null) { var role = new GroupTypeRoleService(rockContext).Get(ownerRoleId); if (role != null && role.GroupTypeId.HasValue) { var groupMember = new GroupMember(); groupMember.PersonId = familyMember.Person.Id; groupMember.GroupRoleId = role.Id; group = new Group(); group.Name = role.GroupType.Name; group.GroupTypeId = role.GroupTypeId.Value; group.Members.Add(groupMember); groupService.Add(group); } } // add the visitor to this group with CanCheckIn Person.CreateCheckinRelationship(familyMember.Person.Id, personId, CurrentPersonAlias); } rockContext.SaveChanges(); }
private void ChooseFamily(string familyIdAsString) { int familyId = Int32.Parse(familyIdAsString); CurrentCheckInState = ( CheckInState )Session["CheckInState"]; ClearSelection(); CheckInFamily selectedFamily = CurrentCheckInState.CheckIn.Families.FirstOrDefault(f => f.Group.Id == familyId); if (selectedFamily != null) { try { //clear QCPeople session object and get it ready for quick checkin. Session.Remove("qcPeople"); } catch { } selectedFamily.Selected = true; SaveState(); NavigateToNextPage(); } }
/// <summary> /// Processes this action for a check-in family. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="family">The family.</param> public static void ProcessForFamily( RockContext rockContext, CheckInFamily family ) { if ( family != null ) { foreach ( var person in family.People ) { foreach ( var groupType in person.GroupTypes ) { foreach ( var group in groupType.Groups ) { foreach ( var location in group.Locations ) { location.AvailableForSchedule = location.Schedules .Where( s => !s.ExcludedByFilter ) .Select( s => s.Schedule.Id ) .ToList(); } group.AvailableForSchedule = group.Locations .Where( l => !l.ExcludedByFilter ) .SelectMany( l => l.AvailableForSchedule ) .Distinct() .ToList(); } groupType.AvailableForSchedule = groupType.Groups .Where( l => !l.ExcludedByFilter ) .SelectMany( l => l.AvailableForSchedule ) .Distinct() .ToList(); } } } }
/// <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, Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null && checkInState.CheckIn.SearchType != null) { checkInState.CheckIn.Families = new List <CheckInFamily>(); if (!string.IsNullOrWhiteSpace(checkInState.CheckIn.SearchValue)) { var personService = new PersonService(rockContext); var memberService = new GroupMemberService(rockContext); var groupService = new GroupService(rockContext); int personRecordTypeId = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid()).Id; int familyGroupTypeId = GroupTypeCache.Read(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()).Id; var dvInactive = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid()); IQueryable <int> familyIdQry = null; if (checkInState.CheckIn.SearchType.Guid.Equals(SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER.AsGuid())) { string numericPhone = checkInState.CheckIn.SearchValue.AsNumeric(); var phoneQry = new PhoneNumberService(rockContext).Queryable().AsNoTracking(); if (checkInState.CheckInType == null || checkInState.CheckInType.PhoneSearchType == PhoneSearchType.EndsWith) { char[] charArray = numericPhone.ToCharArray(); Array.Reverse(charArray); phoneQry = phoneQry.Where(o => o.NumberReversed.StartsWith(new string( charArray ))); } else { phoneQry = phoneQry.Where(o => o.Number.Contains(numericPhone)); } var tmpQry = phoneQry.Join(personService.Queryable().AsNoTracking(), o => new { PersonId = o.PersonId, IsDeceased = false, RecordTypeValueId = personRecordTypeId }, p => new { PersonId = p.Id, IsDeceased = p.IsDeceased, RecordTypeValueId = p.RecordTypeValueId.Value }, (pn, p) => new { Person = p, PhoneNumber = pn }) .Join(memberService.Queryable().AsNoTracking(), pn => pn.Person.Id, m => m.PersonId, (o, m) => new { PersonNumber = o.PhoneNumber, GroupMember = m }); familyIdQry = groupService.Queryable().Where(g => tmpQry.Any(o => o.GroupMember.GroupId == g.Id) && g.GroupTypeId == familyGroupTypeId) .Select(g => g.Id) .Distinct(); } else { var familyMemberQry = memberService .Queryable().AsNoTracking() .Where(m => m.Group.GroupTypeId == familyGroupTypeId && m.Person.RecordTypeValueId == personRecordTypeId); if (checkInState.CheckIn.SearchType.Guid.Equals(SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_NAME.AsGuid())) { var personIds = personService.GetByFullName(checkInState.CheckIn.SearchValue, false).AsNoTracking().Select(p => p.Id); familyMemberQry = familyMemberQry.Where(f => personIds.Contains(f.PersonId)); } else if (checkInState.CheckIn.SearchType.Guid.Equals(SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_SCANNED_ID.AsGuid())) { var entityIds = new List <int>(); var attributeValueService = new AttributeValueService(rockContext); var attr = AttributeCache.Read(SystemGuid.Attribute.FAMILY_CHECKIN_IDENTIFIERS.AsGuid()); if (attr != null) { entityIds = new AttributeValueService(rockContext) .Queryable().AsNoTracking() .Where(v => v.AttributeId == attr.Id && v.EntityId.HasValue && ("|" + v.Value + "|").Contains("|" + checkInState.CheckIn.SearchValue + "|")) .Select(v => v.EntityId.Value) .ToList(); } familyMemberQry = familyMemberQry.Where(f => entityIds.Contains(f.GroupId)); } else if (checkInState.CheckIn.SearchType.Guid.Equals(SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_FAMILY_ID.AsGuid())) { List <int> searchFamilyIds = checkInState.CheckIn.SearchValue.SplitDelimitedValues().AsIntegerList(); familyMemberQry = familyMemberQry.Where(f => searchFamilyIds.Contains(f.GroupId)); } else { errorMessages.Add("Invalid Search Type"); return(false); } familyIdQry = familyMemberQry .Select(m => m.GroupId) .Distinct(); } int maxResults = checkInState.CheckInType != null ? checkInState.CheckInType.MaxSearchResults : 100; if (maxResults > 0) { familyIdQry = familyIdQry.Take(maxResults); } var familyIds = familyIdQry.ToList(); // Load the family members var familyMembers = memberService .Queryable("Group,GroupRole,Person").AsNoTracking() .Where(m => familyIds.Contains(m.GroupId)) .ToList(); // Add each family foreach (int familyId in familyIds) { // Get each of the members for this family var familyMemberQry = familyMembers .Where(m => m.GroupId == familyId && m.Person.NickName != null); if (checkInState.CheckInType != null && checkInState.CheckInType.PreventInactivePeople && dvInactive != null) { familyMemberQry = familyMemberQry .Where(m => m.Person.RecordStatusValueId != dvInactive.Id); } var thisFamilyMembers = familyMemberQry.ToList(); if (thisFamilyMembers.Any()) { var group = thisFamilyMembers .Select(m => m.Group) .FirstOrDefault(); var firstNames = thisFamilyMembers .OrderBy(m => m.GroupRole.Order) .ThenBy(m => m.Person.BirthYear) .ThenBy(m => m.Person.BirthMonth) .ThenBy(m => m.Person.BirthDay) .ThenBy(m => m.Person.Gender) .Select(m => m.Person.NickName) .ToList(); var family = new CheckInFamily(); family.Group = group.Clone(false); family.Caption = group.ToString(); family.SubCaption = firstNames.AsDelimited(", "); checkInState.CheckIn.Families.Add(family); } } } return(true); } errorMessages.Add("Invalid Check-in State"); return(false); }
/// <summary> /// Processes this action for a check-in family. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="family">The family.</param> /// <param name="preventDuplicateCheckin">if set to <c>true</c> [prevent duplicate checkin].</param> /// <returns></returns> public static bool ProcessForFamily(RockContext rockContext, CheckInFamily family, bool preventDuplicateCheckin) { if (family != null) { var personIds = family.People.Select(p => p.Person.Id).ToList(); var today = RockDateTime.Today; var tomorrow = RockDateTime.Today.AddDays(1); var existingAttendance = new AttendanceService(rockContext) .Queryable().AsNoTracking() .Where(a => a.StartDateTime.CompareTo(today) >= 0 && a.StartDateTime.CompareTo(tomorrow) < 0 && a.DidAttend.HasValue && a.DidAttend.Value && !a.EndDateTime.HasValue && a.PersonAlias != null && personIds.Contains(a.PersonAlias.PersonId) && a.Occurrence.ScheduleId.HasValue) .Select(a => new { PersonId = a.PersonAlias.PersonId, ScheduleId = a.Occurrence.ScheduleId.Value }) .ToList(); if (existingAttendance.Any()) { foreach (var person in family.People.ToList()) { var attendedScheduleIds = existingAttendance.Where(a => a.PersonId == person.Person.Id).Select(a => a.ScheduleId).ToList(); if (attendedScheduleIds.Any()) { foreach (var groupType in person.GroupTypes.ToList()) { if (preventDuplicateCheckin || groupType.GroupType.GetAttributeValue("PreventDuplicateCheckin").AsBoolean()) { attendedScheduleIds.ForEach(s => groupType.AvailableForSchedule.Remove(s)); if (!groupType.AvailableForSchedule.Any()) { person.GroupTypes.Remove(groupType); } else { foreach (var group in groupType.Groups.ToList()) { attendedScheduleIds.ForEach(s => group.AvailableForSchedule.Remove(s)); if (!group.AvailableForSchedule.Any()) { groupType.Groups.Remove(group); } else { foreach (var location in group.Locations.ToList()) { attendedScheduleIds.ForEach(s => location.AvailableForSchedule.Remove(s)); if (!location.AvailableForSchedule.Any()) { group.Locations.Remove(location); } else { foreach (var schedule in location.Schedules) { if (schedule.PreSelected && !location.AvailableForSchedule.Contains(schedule.Schedule.Id)) { schedule.PreSelected = false; location.PreSelected = false; group.PreSelected = false; groupType.PreSelected = false; } } } } if (group.Locations.Count == 0) { groupType.Groups.Remove(group); } } } if (groupType.Groups.Count == 0) { person.GroupTypes.Remove(groupType); } } } } if (person.GroupTypes.Count == 0) { family.People.Remove(person); } } } } } return(true); }
/// <summary> /// Adds people who are eligible to check-out into the family's CheckOutPeople collection. /// </summary> /// <param name="checkinSchedules">The check-in schedules.</param> /// <param name="family">The family.</param> /// <param name="person">The person.</param> /// <param name="location">The location.</param> /// <param name="locationAttendance">The location attendance.</param> private static void AddPeopleToFamilyCheckOutPeopleCollection(List <Schedule> checkinSchedules, CheckInFamily family, CheckInPerson person, KioskLocation location, List <PersonAttendanceInfo> locationAttendance) { if (locationAttendance == null || locationAttendance.Count() == 0) { return; } // Find the active (for checkout) schedules for this location (campus) var locationDateTime = RockDateTime.Now; if (location.CampusId.HasValue) { locationDateTime = CampusCache.Get(location.CampusId.Value)?.CurrentDateTime ?? RockDateTime.Now; } var activeForCheckOutScheduleIds = new List <int>(); foreach (var schedule in checkinSchedules) { if (schedule.WasScheduleOrCheckInActiveForCheckOut(locationDateTime)) { activeForCheckOutScheduleIds.Add(schedule.Id); } } // Check to see if the person is still checked into this group-type/group/location combination var activeForCheckOutAttendanceIds = locationAttendance .Where(a => a.StartDateTime > DateTime.Today && a.ScheduleId.HasValue && activeForCheckOutScheduleIds.Contains(a.ScheduleId.Value) && !a.EndDateTime.HasValue) .Select(a => a.AttendanceId) .ToList(); // If so, allow person to check-out. if (activeForCheckOutAttendanceIds.Any()) { var checkOutPerson = family.CheckOutPeople.FirstOrDefault(p => p.Person.Id == person.Person.Id); if (checkOutPerson == null) { checkOutPerson = new CheckOutPerson(); checkOutPerson.Person = person.Person; family.CheckOutPeople.Add(checkOutPerson); } checkOutPerson.AttendanceIds.AddRange(activeForCheckOutAttendanceIds); } }
/// <summary> /// Handles the Click event of the btnSaveFamily 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 btnSaveFamily_Click(object sender, EventArgs e) { if (CurrentCheckInState == null) { // OnLoad would have started a 'NavigateToHomePage', so just jump out return; } if (!EditFamilyState.FamilyPersonListState.Any(x => !x.IsDeleted)) { // Saving a new family, but nobody added to family, so just exit CancelFamilyEdit(false); } if (!this.Page.IsValid) { return; } var rockContext = new RockContext(); // Set the Campus for new families to the Campus of this Kiosk int?kioskCampusId = CurrentCheckInState.Kiosk.CampusId; UpdateFamilyAttributesState(); SetEditableStateAttributes(); FamilyRegistrationState.SaveResult saveResult = null; rockContext.WrapTransaction(() => { saveResult = EditFamilyState.SaveFamilyAndPersonsToDatabase(kioskCampusId, rockContext); }); // Queue up any Workflows that are configured to fire after a new person and/or family is added if (saveResult.NewFamilyList.Any()) { var addFamilyWorkflowTypes = CurrentCheckInState.CheckInType.Registration.AddFamilyWorkflowTypes; // only fire a NewFamily workflow if the Primary family is new (don't fire workflows for any 'Can Checkin' families that were created) var newPrimaryFamily = saveResult.NewFamilyList.FirstOrDefault(a => a.Id == EditFamilyState.GroupId.Value); if (newPrimaryFamily != null) { foreach (var addFamilyWorkflowType in addFamilyWorkflowTypes) { LaunchWorkflowTransaction launchWorkflowTransaction = new LaunchWorkflowTransaction <Group>(addFamilyWorkflowType.Id, newPrimaryFamily.Id); launchWorkflowTransaction.Enqueue(); } } } if (saveResult.NewPersonList.Any()) { var addPersonWorkflowTypes = CurrentCheckInState.CheckInType.Registration.AddPersonWorkflowTypes; foreach (var newPerson in saveResult.NewPersonList) { foreach (var addPersonWorkflowType in addPersonWorkflowTypes) { LaunchWorkflowTransaction launchWorkflowTransaction = new LaunchWorkflowTransaction <Person>(addPersonWorkflowType.Id, newPerson.Id); launchWorkflowTransaction.Enqueue(); } } } if (CurrentCheckInState.CheckInType.Registration.EnableCheckInAfterRegistration) { upContent.Update(); mdEditFamily.Hide(); // un-disable any IdleRedirect blocks DisableIdleRedirectBlocks(false); var currentFamily = CurrentCheckInState.CheckIn.Families.FirstOrDefault(a => a.Group.Id == EditFamilyState.GroupId); if (currentFamily == null) { // if this is a new family, add it to the Checkin.Families so that the CurrentFamily wil be set to the new family currentFamily = new CheckInFamily() { Selected = true }; currentFamily.Group = new GroupService(rockContext).GetNoTracking(EditFamilyState.GroupId.Value).Clone(false); CurrentCheckInState.CheckIn.Families.Add(currentFamily); } if (currentFamily.Selected) { currentFamily.People.Clear(); // execute the workflow activity that is configured for this block (probably 'Person Search') so that // the checkin state gets updated with any changes we made in Edit Family string workflowActivity = GetAttributeValue("WorkflowActivity"); List <string> errorMessages; if (!string.IsNullOrEmpty(workflowActivity)) { // just in case this is a new family, or family name or phonenumber was changed, update the search to match the updated values if (CurrentCheckInState.CheckIn.SearchType.Guid == Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_NAME.AsGuid()) { var firstFamilyPerson = EditFamilyState.FamilyPersonListState.OrderBy(a => a.IsAdult).FirstOrDefault(); if (firstFamilyPerson != null) { CurrentCheckInState.CheckIn.SearchValue = firstFamilyPerson.FullNameForSearch; } } if (CurrentCheckInState.CheckIn.SearchType.Guid == Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER.AsGuid()) { var firstFamilyPersonWithPhone = EditFamilyState.FamilyPersonListState.Where(a => a.MobilePhoneNumber.IsNotNullOrWhiteSpace()).OrderBy(a => a.IsAdult).FirstOrDefault(); if (firstFamilyPersonWithPhone != null) { CurrentCheckInState.CheckIn.SearchValue = firstFamilyPersonWithPhone.MobilePhoneNumber; } } ProcessActivity(workflowActivity, out errorMessages); } } // if the searchBlock is on this page, have it re-search using the person's updated full name var searchBlock = this.RockPage.ControlsOfTypeRecursive <CheckInSearchBlock>().FirstOrDefault(); if (searchBlock != null) { var firstFamilyPerson = EditFamilyState.FamilyPersonListState.OrderBy(a => a.IsAdult).FirstOrDefault(); string searchString; if (firstFamilyPerson != null) { searchString = firstFamilyPerson.FullNameForSearch; } else { searchString = CurrentCheckInState.CheckIn.SearchValue; } searchBlock.ProcessSearch(searchString); } else { // reload the current page so that other blocks will get updated correctly NavigateToCurrentPageReference(); } } else { upContent.Update(); NavigateToHomePage(); } }
/// <summary> /// Shows the Edit Family block in Edit Family mode /// </summary> /// <param name="checkInFamily">The check in family.</param> public override void ShowEditFamily(CheckInFamily checkInFamily) { ShowFamilyDetail(checkInFamily); }
/// <summary> /// Shows the Edit Family block in Edit Family mode /// </summary> /// <param name="checkInFamily">The check in family.</param> public abstract void ShowEditFamily(CheckInFamily checkInFamily);
/// <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 searchValue = checkInState.CheckIn.SearchValue.Trim(); long n; bool isNumeric = long.TryParse(searchValue, out n); if (isNumeric) { UserLoginService userLogin = new UserLoginService(rockContext); var user = userLogin.GetByUserName(searchValue); if (user != null && GetAttributeValue(action, "SearchByPin").AsBoolean()) { var memberService = new GroupMemberService(rockContext); var families = user.Person.GetFamilies(); foreach (var group in families) { var family = checkInState.CheckIn.Families.Where(f => f.Group.Id == group.Id).FirstOrDefault(); if (family == null) { family = new CheckInFamily(); family.Group = group.Clone(false); family.Group.LoadAttributes(rockContext); family.Caption = group.ToString(); family.SubCaption = ""; checkInState.CheckIn.Families.Add(family); } var person = new CheckInPerson(); person.Person = user.Person; person.Selected = true; family.People = new List <CheckInPerson>() { person }; family.Selected = true; } } else if (GetAttributeValue(action, "SearchByPhone").AsBoolean()) { //Look for person by phone number if (searchValue.Length < (GetAttributeValue(action, "MinimumPhoneLength").AsIntegerOrNull() ?? 7)) { return(false); } PhoneNumberService phoneNumberService = new PhoneNumberService(rockContext); var phoneNumbers = phoneNumberService.GetBySearchterm(searchValue).DistinctBy(pn => pn.PersonId).Take(20).ToList(); foreach (var phoneNumber in phoneNumbers) { var person = phoneNumber.Person; var family = person.GetFamilies().FirstOrDefault(); var cFamily = new CheckInFamily(); cFamily.Group = family.Clone(false); cFamily.Group.LoadAttributes(rockContext); cFamily.Caption = family.ToString(); cFamily.SubCaption = ""; checkInState.CheckIn.Families.Add(cFamily); var cPerson = new CheckInPerson(); cPerson.Person = person; cFamily.People = new List <CheckInPerson>() { cPerson }; } return(true); } } return(true); } errorMessages.Add($"Attempted to run {this.GetType().GetFriendlyTypeName()} in check-in, but the check-in state was null."); return(false); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); RockPage.AddScriptLink("~/Scripts/CheckinClient/checkin-core.js"); if (CurrentWorkflow == null || CurrentCheckInState == null) { NavigateToHomePage(); } else { if (!Page.IsPostBack) { ClearSelection(); var personSchedules = new List <CheckInSchedule>(); var distinctSchedules = new List <CheckInSchedule>(); if (CurrentCheckInType != null && CurrentCheckInType.TypeOfCheckin == TypeOfCheckin.Family) { CheckInFamily family = CurrentCheckInState.CheckIn.CurrentFamily; if (family != null) { foreach (var schedule in family.GetPeople(true).SelectMany(p => p.PossibleSchedules).ToList()) { personSchedules.Add(schedule); if (!distinctSchedules.Any(s => s.Schedule.Id == schedule.Schedule.Id)) { distinctSchedules.Add(schedule); } } } else { GoBack(); } lTitle.Text = GetTitleText(); lbSelect.Text = "Next"; lbSelect.Attributes.Add("data-loading-text", "Loading..."); } else { CheckInPerson person = CurrentCheckInState.CheckIn.Families.Where(f => f.Selected).SelectMany(f => f.People.Where(p => p.Selected)).FirstOrDefault(); CheckInGroup group = null; CheckInLocation location = null; if (person != null) { group = person.GroupTypes.Where(t => t.Selected).SelectMany(t => t.Groups.Where(g => g.Selected)).FirstOrDefault(); if (group != null) { location = group.Locations.Where(l => l.Selected).FirstOrDefault(); } } if (location == null) { GoBack(); } lTitle.Text = GetTitleText(); lbSelect.Text = "Check In"; lbSelect.Attributes.Add("data-loading-text", "Printing..."); personSchedules = location.Schedules.Where(s => !s.ExcludedByFilter).ToList(); distinctSchedules = personSchedules; } lCaption.Text = GetAttributeValue(AttributeKey.Caption); if (distinctSchedules.Count == 1) { personSchedules.ForEach(s => s.Selected = true); ProcessSelection(maWarning); } else { string script = string.Format(@" <script> function GetTimeSelection() {{ var ids = ''; $('div.checkin-timelist button.active').each( function() {{ ids += $(this).attr('schedule-id') + ','; }}); if (ids == '') {{ bootbox.alert('Please select at least one time'); return false; }} else {{ $('#{0}').button('loading') $('#{1}').val(ids); return true; }} }} </script> ", lbSelect.ClientID, hfTimes.ClientID); Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "SelectTime", script); rSelection.DataSource = distinctSchedules .OrderBy(s => s.StartTime.Value.TimeOfDay) .ThenBy(s => s.Schedule.Name) .ToList(); rSelection.DataBind(); } } } }
/// <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, Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null) { var personService = new PersonService(rockContext); var memberService = new GroupMemberService(rockContext); Guid familyGroupTypeGuid = SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid(); if (checkInState.CheckIn.SearchType.Guid.Equals(new Guid(SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER))) { string numericPhone = checkInState.CheckIn.SearchValue.AsNumeric(); var personRecordTypeId = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid()).Id; // Find the families with any member who has a phone number that contains selected value var familyQry = memberService .Queryable().AsNoTracking() .Where(m => m.Group.GroupType.Guid.Equals(familyGroupTypeGuid) && m.Person.RecordTypeValueId == personRecordTypeId); int?phoneSearchType = GetAttributeValue(action, "PhoneSearchType").AsIntegerOrNull(); if (phoneSearchType.HasValue && phoneSearchType.Value == 1) { familyQry = familyQry.Where(m => m.Person.PhoneNumbers.Any(n => n.Number.EndsWith(numericPhone))); } else { familyQry = familyQry.Where(m => m.Person.PhoneNumbers.Any(n => n.Number.Contains(numericPhone))); } var familyIdQry = familyQry .Select(m => m.GroupId) .Distinct(); int maxResults = GetAttributeValue(action, "MaxResults").AsInteger(); if (maxResults > 0) { familyIdQry = familyIdQry.Take(maxResults); } var familyIds = familyIdQry.ToList(); // Load the family members var familyMembers = memberService .Queryable("Group,GroupRole,Person").AsNoTracking() .Where(m => familyIds.Contains(m.GroupId)) .ToList(); // Add each family foreach (int familyId in familyIds) { // Get each of the members for this family var thisFamilyMembers = familyMembers .Where(m => m.GroupId == familyId && m.Person.NickName != null) .ToList(); if (thisFamilyMembers.Any()) { var group = thisFamilyMembers .Select(m => m.Group) .FirstOrDefault(); var firstNames = thisFamilyMembers .OrderBy(m => m.GroupRole.Order) .ThenBy(m => m.Person.BirthYear) .ThenBy(m => m.Person.BirthMonth) .ThenBy(m => m.Person.BirthDay) .ThenBy(m => m.Person.Gender) .Select(m => m.Person.NickName) .ToList(); var family = new CheckInFamily(); family.Group = group.Clone(false); family.Caption = group.ToString(); family.SubCaption = firstNames.AsDelimited(", "); checkInState.CheckIn.Families.Add(family); } } } else if (checkInState.CheckIn.SearchType.Guid.Equals(new Guid(SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_NAME))) { foreach (var person in personService.GetByFullName(checkInState.CheckIn.SearchValue, false).AsNoTracking()) { foreach (var group in person.Members.Where(m => m.Group.GroupType.Guid.Equals(familyGroupTypeGuid)).Select(m => m.Group).ToList()) { var family = checkInState.CheckIn.Families.Where(f => f.Group.Id == group.Id).FirstOrDefault(); if (family == null) { family = new CheckInFamily(); family.Group = group.Clone(false); family.Group.LoadAttributes(rockContext); family.Caption = group.ToString(); family.SubCaption = memberService.GetFirstNames(group.Id).ToList().AsDelimited(", "); checkInState.CheckIn.Families.Add(family); } } } } else { errorMessages.Add("Invalid Search Type"); return(false); } return(true); } errorMessages.Add("Invalid Check-in State"); return(false); }
private CheckInStatus DehydrateStatus(CheckInStatus status) { var checkinstatus = new CheckInStatus { SearchType = status.SearchType, SearchValue = status.SearchValue, Families = new List <CheckInFamily>() }; foreach (var family in status.Families) { var checkinFamily = new CheckInFamily() { Selected = family.Selected, Caption = family.Caption, SubCaption = family.SubCaption, AttendanceIds = family.AttendanceIds, FirstNames = family.FirstNames, Group = new Group() { Id = family.Group.Id }, People = new List <CheckInPerson>() }; checkinstatus.Families.Add(checkinFamily); foreach (var person in family.People) { var checkInPerson = new CheckInPerson { GroupTypes = new List <CheckInGroupType>(), FirstTime = person.FirstTime, FamilyMember = person.FamilyMember, Person = new Person { Id = person.Person.Id }, PreSelected = person.PreSelected, SecurityCode = person.SecurityCode, ExcludedByFilter = person.ExcludedByFilter, Selected = person.Selected }; checkinFamily.People.Add(checkInPerson); foreach (var grouptype in person.GroupTypes) { var checkinGroupType = new CheckInGroupType { GroupType = grouptype.GroupType, Selected = grouptype.Selected, PreSelected = grouptype.PreSelected, ExcludedByFilter = grouptype.ExcludedByFilter, Groups = new List <CheckInGroup>() }; checkInPerson.GroupTypes.Add(checkinGroupType); foreach (var group in grouptype.Groups) { var checkinGroup = new CheckInGroup { Group = new Group { Id = group.Group.Id }, Selected = group.Selected, PreSelected = group.PreSelected, ExcludedByFilter = group.ExcludedByFilter, Locations = new List <CheckInLocation>() }; checkinGroupType.Groups.Add(group); foreach (var location in group.Locations) { var checkinLocation = new CheckInLocation { Location = new Location { Id = location.Location.Id }, Selected = location.Selected, PreSelected = location.PreSelected, ExcludedByFilter = location.ExcludedByFilter, CampusId = location.CampusId, Schedules = new List <CheckInSchedule>() }; checkinGroup.Locations.Add(checkinLocation); foreach (var schedule in location.Schedules) { var checkinSchedule = new CheckInSchedule { Schedule = new Schedule { Id = schedule.Schedule.Id }, Selected = schedule.Selected, PreSelected = schedule.PreSelected, ExcludedByFilter = schedule.ExcludedByFilter, CampusId = schedule.CampusId, StartTime = schedule.StartTime }; checkinLocation.Schedules.Add(checkinSchedule); } } } } } } return(checkinstatus); }
/// <summary> /// Shows edit UI fo the family (or null adding a new family) /// </summary> /// <param name="checkInFamily">The check in family.</param> private void ShowFamilyDetail(CheckInFamily checkInFamily) { if (checkInFamily != null && checkInFamily.Group != null) { this.EditFamilyState = FamilyRegistrationState.FromGroup(checkInFamily.Group); hfGroupId.Value = checkInFamily.Group.Id.ToString(); mdEditFamily.Title = checkInFamily.Group.Name; int groupId = hfGroupId.Value.AsInteger(); var rockContext = new RockContext(); var groupMemberService = new GroupMemberService(rockContext); var groupMembersQuery = groupMemberService.Queryable(false) .Include(a => a.Person) .Where(a => a.GroupId == groupId) .OrderBy(m => m.GroupRole.Order) .ThenBy(m => m.Person.BirthYear) .ThenBy(m => m.Person.BirthMonth) .ThenBy(m => m.Person.BirthDay) .ThenBy(m => m.Person.Gender); var groupMemberList = groupMembersQuery.ToList(); foreach (var groupMember in groupMemberList) { var familyPersonState = FamilyRegistrationState.FamilyPersonState.FromPerson(groupMember.Person, 0, true); familyPersonState.GroupMemberGuid = groupMember.Guid; familyPersonState.GroupId = groupMember.GroupId; familyPersonState.IsAdult = groupMember.GroupRoleId == _groupTypeRoleAdultId; this.EditFamilyState.FamilyPersonListState.Add(familyPersonState); } var adultIds = this.EditFamilyState.FamilyPersonListState.Where(a => a.IsAdult && a.PersonId.HasValue).Select(a => a.PersonId.Value).ToList(); var roleIds = CurrentCheckInState.CheckInType.Registration.KnownRelationships.Where(a => a.Key != 0).Select(a => a.Key).ToList(); IEnumerable <GroupMember> personRelationships = new PersonService(rockContext).GetRelatedPeople(adultIds, roleIds); foreach (GroupMember personRelationship in personRelationships) { if (!this.EditFamilyState.FamilyPersonListState.Any(a => a.PersonId == personRelationship.Person.Id)) { var familyPersonState = FamilyRegistrationState.FamilyPersonState.FromPerson(personRelationship.Person, personRelationship.GroupRoleId, false); familyPersonState.GroupMemberGuid = Guid.NewGuid(); var relatedFamily = personRelationship.Person.GetFamily(); if (relatedFamily != null) { familyPersonState.GroupId = relatedFamily.Id; } familyPersonState.IsAdult = false; familyPersonState.ChildRelationshipToAdult = personRelationship.GroupRoleId; familyPersonState.CanCheckIn = CurrentCheckInState.CheckInType.Registration.KnownRelationshipsCanCheckin.Any(k => k.Key == familyPersonState.ChildRelationshipToAdult); this.EditFamilyState.FamilyPersonListState.Add(familyPersonState); } } BindFamilyMembersGrid(); CreateDynamicFamilyControls(EditFamilyState); ShowFamilyView(); } else { this.EditFamilyState = FamilyRegistrationState.FromGroup(new Group() { GroupTypeId = GroupTypeCache.GetFamilyGroupType().Id }); CreateDynamicFamilyControls(EditFamilyState); hfGroupId.Value = "0"; mdEditFamily.Title = "Add Family"; EditGroupMember(null); } _initialEditFamilyStateHash = this.EditFamilyState.GetStateHash(); // disable any idle redirect blocks that are on the page when the mdEditFamily modal is open DisableIdleRedirectBlocks(true); upContent.Update(); mdEditFamily.Show(); }
/// <summary> /// Handles the Click event of the bbtnCheckin 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 bbtnCheckin_Click(object sender, EventArgs e) { UpdateConfigurationFromBlockSettings(); // checkin status might have changed after the Checkin Button was displayed, so make sure the kiosk is still active var checkinStatus = CheckinConfigurationHelper.GetCheckinStatus(CurrentCheckInState); if (checkinStatus != CheckinConfigurationHelper.CheckinStatus.Active) { RefreshCheckinStatusInformation(checkinStatus); return; } var latitude = hfLatitude.Value.AsDoubleOrNull(); var longitude = hfLongitude.Value.AsDoubleOrNull(); if (latitude == null || longitude == null) { // shouldn't happen return; } var device = GetFirstMatchingKioskByGeoFencing(latitude.Value, longitude.Value); if (device == null) { // shouldn't happen return; } LocalDeviceConfig.CurrentKioskId = device.Id; SaveState(); var checkInState = CurrentCheckInState; checkInState.CheckIn = new CheckInStatus(); checkInState.CheckIn.SearchType = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_FAMILY_ID); var mobilePerson = this.GetMobilePerson(); if (mobilePerson == null) { // shouldn't happen return; } var family = mobilePerson.GetFamily(); var familyMembers = mobilePerson.GetFamilyMembers(true); var firstNames = familyMembers .OrderBy(m => m.GroupRole.Order) .ThenBy(m => m.Person.BirthYear) .ThenBy(m => m.Person.BirthMonth) .ThenBy(m => m.Person.BirthDay) .ThenBy(m => m.Person.Gender) .Select(m => m.Person.NickName) .ToList(); var checkInFamily = new CheckInFamily(); checkInFamily.Group = family.Clone(false); checkInFamily.Caption = family.ToString(); checkInFamily.FirstNames = firstNames; checkInFamily.SubCaption = firstNames.AsDelimited(", "); checkInFamily.Selected = true; checkInState.CheckIn.Families = new List <CheckInFamily>(); checkInState.CheckIn.Families.Add(checkInFamily); var rockContext = new RockContext(); SaveState(); var noMatchingPeopleMessage = this.GetAttributeValue(AttributeKey.NoPeopleMessage); Func <bool> doNotProceedCondition = () => { var noMatchingFamilies = ( CurrentCheckInState.CheckIn.Families.All(f => f.People.Count == 0) && CurrentCheckInState.CheckIn.Families.All(f => f.Action == CheckinAction.CheckIn) // not sure this is needed ) && ( !CurrentCheckInState.AllowCheckout || ( CurrentCheckInState.AllowCheckout && CurrentCheckInState.CheckIn.Families.All(f => f.CheckOutPeople.Count == 0) ) ); if (noMatchingFamilies) { maWarning.Show(noMatchingPeopleMessage, Rock.Web.UI.Controls.ModalAlertType.None); return(true); } else { return(false); } }; ProcessSelection(maWarning, doNotProceedCondition, noMatchingPeopleMessage); }
/// <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 checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null && checkInState.CheckIn.SearchType != null) { var personService = new PersonService(rockContext); var memberService = new GroupMemberService(rockContext); GroupService groupService = new GroupService(rockContext); PhoneNumberService phoneNumberService = new PhoneNumberService(rockContext); int familyGroupTypeId = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()).Id; if (checkInState.CheckIn.SearchType.Guid.Equals(new Guid(Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER))) { string numericPhone = checkInState.CheckIn.SearchValue.AsNumeric(); var personRecordTypeId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid()).Id; // Find the families with any member who has a phone number that contains selected value var familyQry = phoneNumberService.Queryable().AsNoTracking(); if (checkInState.CheckInType == null || checkInState.CheckInType.PhoneSearchType == PhoneSearchType.EndsWith) { char[] charArray = numericPhone.ToCharArray(); Array.Reverse(charArray); familyQry = familyQry.Where(o => o.NumberReversed.StartsWith(new string( charArray ))); } else { familyQry = familyQry.Where(o => o.Number.Contains(numericPhone)); } var tmpQry = familyQry.Join(personService.Queryable().AsNoTracking(), o => new { PersonId = o.PersonId, IsDeceased = false, RecordTypeValueId = personRecordTypeId }, p => new { PersonId = p.Id, IsDeceased = p.IsDeceased, RecordTypeValueId = p.RecordTypeValueId.Value }, (pn, p) => new { Person = p, PhoneNumber = pn }) .Join(memberService.Queryable().AsNoTracking(), pn => pn.Person.Id, m => m.PersonId, (o, m) => new { PersonNumber = o.PhoneNumber, GroupMember = m }); var familyIdQry = groupService.Queryable().Where(g => tmpQry.Any(o => o.GroupMember.GroupId == g.Id) && g.GroupTypeId == familyGroupTypeId) .Select(g => g.Id) .Distinct(); int maxResults = checkInState.CheckInType != null ? checkInState.CheckInType.MaxSearchResults : 100; if (maxResults > 0) { familyIdQry = familyIdQry.Take(maxResults); } var familyIds = familyIdQry.ToList(); // Load the family members var familyMembers = memberService .Queryable("Group,GroupRole,Person").AsNoTracking() .Where(m => familyIds.Contains(m.GroupId)) .ToList(); // Add each family foreach (int familyId in familyIds) { // Get each of the members for this family var thisFamilyMembers = familyMembers .Where(m => m.GroupId == familyId && m.Person.NickName != null) .ToList(); if (thisFamilyMembers.Any()) { var group = thisFamilyMembers .Select(m => m.Group) .FirstOrDefault(); var firstNames = thisFamilyMembers .OrderBy(m => m.GroupRole.Order) .ThenBy(m => m.Person.BirthYear) .ThenBy(m => m.Person.BirthMonth) .ThenBy(m => m.Person.BirthDay) .ThenBy(m => m.Person.Gender) .Select(m => m.Person.NickName) .ToList(); var family = new CheckInFamily(); family.Group = group.Clone(false); family.Caption = group.ToString(); family.SubCaption = firstNames.AsDelimited(", "); checkInState.CheckIn.Families.Add(family); } } } else if (checkInState.CheckIn.SearchType.Guid.Equals(new Guid(Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_NAME))) { foreach (var person in personService.GetByFullName(checkInState.CheckIn.SearchValue, false).AsNoTracking()) { foreach (var group in person.Members.Where(m => m.Group.GroupTypeId == familyGroupTypeId).Select(m => m.Group).ToList()) { var family = checkInState.CheckIn.Families.Where(f => f.Group.Id == group.Id).FirstOrDefault(); if (family == null) { family = new CheckInFamily(); family.Group = group.Clone(false); family.Group.LoadAttributes(rockContext); family.Caption = group.ToString(); family.SubCaption = memberService.GetFirstNames(group.Id).ToList().AsDelimited(", "); checkInState.CheckIn.Families.Add(family); } } } } else { errorMessages.Add("Invalid Search Type"); return(false); } return(true); } errorMessages.Add("Invalid Check-in State"); return(false); }
/// <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, Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null && checkInState.CheckIn.SearchType != null) { checkInState.CheckIn.Families = new List <CheckInFamily>(); if (!string.IsNullOrWhiteSpace(checkInState.CheckIn.SearchValue)) { var personService = new PersonService(rockContext); var memberService = new GroupMemberService(rockContext); var groupService = new GroupService(rockContext); int personRecordTypeId = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid()).Id; int familyGroupTypeId = GroupTypeCache.Get(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()).Id; var dvInactive = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_INACTIVE.AsGuid()); IQueryable <int> familyIdQry = null; if (checkInState.CheckIn.SearchType.Guid.Equals(SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER.AsGuid())) { string numericPhone = checkInState.CheckIn.SearchValue.AsNumeric(); var phoneQry = new PhoneNumberService(rockContext).Queryable().AsNoTracking(); if (checkInState.CheckInType == null || checkInState.CheckInType.PhoneSearchType == PhoneSearchType.EndsWith) { char[] charArray = numericPhone.ToCharArray(); Array.Reverse(charArray); phoneQry = phoneQry.Where(o => o.NumberReversed.StartsWith(new string( charArray ))); } else { phoneQry = phoneQry.Where(o => o.Number.Contains(numericPhone)); } var tmpQry = phoneQry.Join(personService.Queryable().AsNoTracking(), o => new { PersonId = o.PersonId, IsDeceased = false, RecordTypeValueId = personRecordTypeId }, p => new { PersonId = p.Id, IsDeceased = p.IsDeceased, RecordTypeValueId = p.RecordTypeValueId.Value }, (pn, p) => new { Person = p, PhoneNumber = pn }) .Join(memberService.Queryable().AsNoTracking(), pn => pn.Person.Id, m => m.PersonId, (o, m) => new { PersonNumber = o.PhoneNumber, GroupMember = m }); familyIdQry = groupService.Queryable().Where(g => tmpQry.Any(o => o.GroupMember.GroupId == g.Id) && g.GroupTypeId == familyGroupTypeId) .Select(g => g.Id) .Distinct(); } else { var familyMemberQry = memberService .AsNoFilter().AsNoTracking() .Where(m => m.Group.GroupTypeId == familyGroupTypeId && m.Person.RecordTypeValueId == personRecordTypeId); if (checkInState.CheckIn.SearchType.Guid.Equals(SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_NAME.AsGuid())) { var personIds = personService.GetByFullName(checkInState.CheckIn.SearchValue, false).AsNoTracking().Select(p => p.Id); familyMemberQry = familyMemberQry.Where(f => personIds.Contains(f.PersonId)); } else if (checkInState.CheckIn.SearchType.Guid.Equals(SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_SCANNED_ID.AsGuid())) { var personIds = new List <int>(); var dv = DefinedValueCache.Get(SystemGuid.DefinedValue.PERSON_SEARCH_KEYS_ALTERNATE_ID.AsGuid()); if (dv != null) { var searchValueService = new PersonSearchKeyService(rockContext); var personAliases = searchValueService.Queryable().AsNoTracking() .Where(v => v.SearchTypeValueId == dv.Id && v.SearchValue == checkInState.CheckIn.SearchValue) .Select(v => v.PersonAlias); if (personAliases.Any()) { checkInState.CheckIn.CheckedInByPersonAliasId = personAliases.First().Id; personIds = personAliases.Select(a => a.PersonId).ToList(); } } if (personIds.Any()) { familyMemberQry = familyMemberQry.Where(f => personIds.Contains(f.PersonId)); } else { // if there were no matches, try to find a family check-in identifier. V8 has a "run once" job that moves the family identifiers // to person search values, but in case the job has not yet completed, will still do the check for family ids. var entityIds = new List <int>(); var attributeValueService = new AttributeValueService(rockContext); var attr = AttributeCache.Get("8F528431-A438-4488-8DC3-CA42E66C1B37".AsGuid()); if (attr != null) { entityIds = new AttributeValueService(rockContext) .Queryable().AsNoTracking() .Where(v => v.AttributeId == attr.Id && v.EntityId.HasValue && ("|" + v.Value + "|").Contains("|" + checkInState.CheckIn.SearchValue + "|")) .Select(v => v.EntityId.Value) .ToList(); } familyMemberQry = familyMemberQry.Where(f => entityIds.Contains(f.GroupId)); } } else if (checkInState.CheckIn.SearchType.Guid.Equals(SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_FAMILY_ID.AsGuid())) { List <int> searchFamilyIds = checkInState.CheckIn.SearchValue.SplitDelimitedValues().AsIntegerList(); familyMemberQry = familyMemberQry.Where(f => searchFamilyIds.Contains(f.GroupId)); } else { errorMessages.Add("Invalid Search Type"); return(false); } familyIdQry = familyMemberQry .Select(m => m.GroupId) .Distinct(); } int maxResults = checkInState.CheckInType != null ? checkInState.CheckInType.MaxSearchResults : 100; if (maxResults > 0) { familyIdQry = familyIdQry.Take(maxResults); } // You might think we should do a ToList() on the familyIdQry and use it below, // but through some extensive testing, we discovered that the next SQL query is better // optimized if it has the familyIdQry without being to-listed. It was over 270% slower // when querying names and 120% slower when querying phone numbers. // Load the family members var familyMembers = memberService .Queryable().AsNoTracking() .Where(m => m.Group.GroupTypeId == familyGroupTypeId && familyIdQry.Contains(m.GroupId)).Select(a => new { Group = a.Group, GroupId = a.GroupId, Order = a.GroupRole.Order, BirthYear = a.Person.BirthYear, BirthMonth = a.Person.BirthMonth, BirthDay = a.Person.BirthDay, Gender = a.Person.Gender, NickName = a.Person.NickName, RecordStatusValueId = a.Person.RecordStatusValueId }) .ToList(); // Add each family foreach (int familyId in familyMembers.Select(fm => fm.GroupId).Distinct()) { // Get each of the members for this family var familyMemberQry = familyMembers .Where(m => m.GroupId == familyId && m.NickName != null); if (checkInState.CheckInType != null && checkInState.CheckInType.PreventInactivePeople && dvInactive != null) { familyMemberQry = familyMemberQry .Where(m => m.RecordStatusValueId != dvInactive.Id); } var thisFamilyMembers = familyMemberQry.ToList(); if (thisFamilyMembers.Any()) { var group = thisFamilyMembers .Select(m => m.Group) .FirstOrDefault(); var firstNames = thisFamilyMembers .OrderBy(m => m.Order) .ThenBy(m => m.BirthYear) .ThenBy(m => m.BirthMonth) .ThenBy(m => m.BirthDay) .ThenBy(m => m.Gender) .Select(m => m.NickName) .ToList(); var family = new CheckInFamily(); family.Group = group.Clone(false); family.Caption = group.ToString(); family.FirstNames = firstNames; family.SubCaption = firstNames.AsDelimited(", "); checkInState.CheckIn.Families.Add(family); } } } return(true); } errorMessages.Add("Invalid Check-in State"); return(false); }