Example #1
0
        /// <summary>
        /// Cancels the family edit.
        /// </summary>
        /// <param name="promptIfChangesMade">if set to <c>true</c> [prompt if changes made].</param>
        private void CancelFamilyEdit(bool promptIfChangesMade)
        {
            if (promptIfChangesMade)
            {
                UpdateFamilyAttributesState();
                int currentEditFamilyStateHash = EditFamilyState.GetStateHash();
                if (_initialEditFamilyStateHash != currentEditFamilyStateHash)
                {
                    hfShowCancelEditPrompt.Value = "1";
                    upContent.Update();
                    return;
                }
            }

            upContent.Update();
            mdEditFamily.Hide();

            // un-disable any IdleRedirect blocks
            DisableIdleRedirectBlocks(false);
        }
Example #2
0
        /// <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();
            }
        }
Example #3
0
 /// <summary>
 /// Saves any user control view-state changes that have occurred since the last page postback.
 /// </summary>
 /// <returns>
 /// Returns the user control's current view state. If there is no view state associated with the control, it returns null.
 /// </returns>
 protected override object SaveViewState()
 {
     this.ViewState["EditFamilyState"] = EditFamilyState.ToJson();
     return(base.SaveViewState());
 }