コード例 #1
0
        /// <summary>
        /// Prays for the specified request and optionally launches a workflow
        /// and/or records an interaction.
        /// </summary>
        /// <param name="prayerRequestGuid">The prayer request unique identifier that is being prayed for.</param>
        /// <param name="currentPerson">The current person whom is performing the action.</param>
        /// <param name="launchWorkflowGuid">The workflow type unique identifier to be launched.</param>
        /// <param name="recordInteraction">If set to <c>true</c> then an interaction will be recorded.</param>
        /// <param name="interactionSummary">The interaction summary text.</param>
        /// <param name="userAgent">The user agent for the interaction.</param>
        /// <param name="clientIpAddress">The client IP address for the interaction.</param>
        /// <param name="sessionGuid">The session unique identifier for the interaction.</param>
        /// <exception cref="System.ArgumentNullException">prayerRequest</exception>
        private static bool PrayForRequest(Guid prayerRequestGuid, Person currentPerson, Guid?launchWorkflowGuid, bool recordInteraction, string interactionSummary, string userAgent, string clientIpAddress, Guid?sessionGuid)
        {
            using (var rockContext = new RockContext())
            {
                var prayerRequestService = new PrayerRequestService(rockContext);
                var prayerRequest        = prayerRequestService.Get(prayerRequestGuid);

                if (prayerRequest == null)
                {
                    return(false);
                }

                prayerRequest.PrayerCount = (prayerRequest.PrayerCount ?? 0) + 1;

                rockContext.SaveChanges();

                if (launchWorkflowGuid.HasValue)
                {
                    PrayerRequestService.LaunchPrayedForWorkflow(prayerRequest, launchWorkflowGuid.Value, currentPerson);
                }

                if (recordInteraction)
                {
                    PrayerRequestService.EnqueuePrayerInteraction(prayerRequest, currentPerson, interactionSummary, userAgent, clientIpAddress, sessionGuid);
                }

                return(true);
            }
        }
コード例 #2
0
        /// <summary>
        /// Displays the details for a single, given prayer request.
        /// </summary>
        /// <param name="prayerRequest">The prayer request.</param>
        /// <param name="rockContext">The rock context.</param>
        private void ShowPrayerRequest(PrayerRequest prayerRequest, RockContext rockContext)
        {
            pnlPrayer.Visible = true;

            prayerRequest.PrayerCount = (prayerRequest.PrayerCount ?? 0) + 1;
            hlblPrayerCountTotal.Text = prayerRequest.PrayerCount.ToString() + " team prayers";
            hlblUrgent.Visible        = prayerRequest.IsUrgent ?? false;

            if (CampusCache.All(false).Count() > 1)
            {
                hlblCampus.Text = prayerRequest.CampusId.HasValue ? prayerRequest.Campus.Name : string.Empty;
            }

            hlblCategory.Text = prayerRequest.Category.Name;
            var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson, new Rock.Lava.CommonMergeFieldsOptions {
                GetLegacyGlobalMergeFields = false
            });

            // need to load attributes so that lava can loop thru PrayerRequest.Attributes
            prayerRequest.LoadAttributes();

            // Filter to only show attribute / attribute values that the person is authorized to view.
            var excludeForView = prayerRequest.Attributes.Where(a => !a.Value.IsAuthorized(Authorization.VIEW, this.CurrentPerson)).Select(a => a.Key).ToList();

            prayerRequest.Attributes      = prayerRequest.Attributes.Where(a => !excludeForView.Contains(a.Key)).ToDictionary(k => k.Key, k => k.Value);
            prayerRequest.AttributeValues = prayerRequest.AttributeValues.Where(av => !excludeForView.Contains(av.Key)).ToDictionary(k => k.Key, k => k.Value);

            mergeFields.Add("PrayerRequest", prayerRequest);
            string prayerPersonLava  = this.GetAttributeValue(AttributeKey.PrayerPersonLava);
            string prayerDisplayLava = this.GetAttributeValue(AttributeKey.PrayerDisplayLava);

            lPersonLavaOutput.Text = prayerPersonLava.ResolveMergeFields(mergeFields);
            lPrayerLavaOutput.Text = prayerDisplayLava.ResolveMergeFields(mergeFields);

            pnlPrayerComments.Visible = prayerRequest.AllowComments ?? false;
            if (notesComments.Visible)
            {
                notesComments.NoteOptions.EntityId = prayerRequest.Id;
            }

            CurrentPrayerRequestId = prayerRequest.Id;

            if (GetAttributeValue(AttributeKey.CreateInteractionsForPrayers).AsBoolean())
            {
                PrayerRequestService.EnqueuePrayerInteraction(prayerRequest, CurrentPerson, PageCache.Layout.Site.Name, Request.UserAgent, RockPage.GetClientIpAddress(), RockPage.Session["RockSessionId"]?.ToString().AsGuidOrNull());
            }

            try
            {
                // save because the prayer count was just modified.
                rockContext.SaveChanges();
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, Context, this.RockPage.PageId, this.RockPage.Site.Id, CurrentPersonAlias);
            }
        }
コード例 #3
0
        /// <summary>
        /// Pray Request.
        /// </summary>
        private void PrayRequest(int prayerRequestId)
        {
            var           rockContext = new RockContext();
            var           service     = new PrayerRequestService(rockContext);
            var           flagLimit   = GetAttributeValue(AttributeKey.FlagLimit).AsIntegerOrNull() ?? 1;
            PrayerRequest request     = service.Get(prayerRequestId);

            if (request != null)
            {
                request.PrayerCount = (request.PrayerCount ?? 0) + 1;
                rockContext.SaveChanges();

                StartWorkflow(request, rockContext, AttributeKey.PrayedWorkflow);
                PrayerRequestService.EnqueuePrayerInteraction(request, CurrentPerson, PageCache.Layout.Site.Name, Request.UserAgent, RockPage.GetClientIpAddress(), RockPage.Session["RockSessionId"]?.ToString().AsGuidOrNull());
            }
        }
コード例 #4
0
        /// <summary>
        /// Builds the content to be shown.
        /// </summary>
        /// <param name="context">The session context.</param>
        /// <returns>
        /// A string containing the XAML content.
        /// </returns>
        protected virtual string BuildContent(string context = null)
        {
            var            template    = Template;
            var            mergeFields = RequestContext.GetCommonMergeFields();
            SessionContext sessionContext;
            PrayerRequest  request;
            var            rockContext = new RockContext();

            if (context.IsNotNullOrWhiteSpace())
            {
                var prayerRequestService = new PrayerRequestService(rockContext);

                sessionContext = Encryption.DecryptString(context).FromJsonOrNull <SessionContext>();

                //
                // Update the prayer count on the last prayer request.
                //
                var lastRequest = prayerRequestService.Get(sessionContext.RequestIds[sessionContext.Index]);
                lastRequest.PrayerCount = (lastRequest.PrayerCount ?? 0) + 1;
                rockContext.SaveChanges();

                if (CreateInteractionsForPrayers)
                {
                    PrayerRequestService.EnqueuePrayerInteraction(lastRequest, RequestContext.CurrentPerson, PageCache.Layout.Site.Name, RequestContext.ClientInformation?.Browser?.String, RequestContext.ClientInformation.IpAddress, null);
                }

                //
                // Move to the next prayer request, or else indicate that we have
                // finished this session.
                //
                sessionContext.Index += 1;
                if (sessionContext.RequestIds.Count > sessionContext.Index)
                {
                    var requestId = sessionContext.RequestIds[sessionContext.Index];
                    request = prayerRequestService.Get(requestId);
                }
                else
                {
                    request = null;
                }
            }
            else
            {
                var query = GetPrayerRequests(rockContext);

                sessionContext = new SessionContext
                {
                    RequestIds = query.Select(a => a.Id).ToList()
                };

                request = query.FirstOrDefault();
            }

            mergeFields.Add("PrayedButtonText", PrayedButtonText);
            mergeFields.Add("ShowFollowButton", ShowFollowButton);
            mergeFields.Add("ShowInappropriateButton", ShowInappropriateButton);
            mergeFields.Add("SessionContext", Encryption.EncryptString(sessionContext.ToJson()));
            mergeFields.Add("Request", request);

            return(template.ResolveMergeFields(mergeFields));
        }